Skip to content

fix: ensure terrainProvider is applied on initial mount via direct ref - #141

Merged
ZTongci merged 3 commits into
alphafrom
fix/globe-terrain-provider-on-mount
Jun 24, 2026
Merged

fix: ensure terrainProvider is applied on initial mount via direct ref#141
ZTongci merged 3 commits into
alphafrom
fix/globe-terrain-provider-on-mount

Conversation

@ZTongci

@ZTongci ZTongci commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Problem

When the Globe component mounts with terrain already enabled — as happens on navigation-back where Apollo cache delivers data synchronously — globe.terrainProvider is never updated from the default EllipsoidTerrainProvider. Terrain tiles never load even though the CesiumTerrainProvider Promise resolves correctly.

Root Cause

Resium's useCesiumComponent applies props (including terrainProvider) through the component's update() function, which is gated behind an internal C.current flag. That flag is set to true by a passive useEffect. However, the initializer I() runs in a microtask (scheduled from useLayoutEffect), which fires before passive effects. So Globe.update() is always skipped on initial mount (C.current === false).

On first page load this is harmless: a workaround in the visualizer layer forced terrain disabled → enabled after a setTimeout(0), producing a prop change that fires after C.current is already true. On navigation-back, Apollo cache delivers scene data synchronously, so setTimeout(0) fires before the Cesium Viewer has recreated its scene and before Globe has mounted as a React child. Globe mounts with terrain already enabled, no subsequent prop change ever occurs, and globe.terrainProvider is never set.

Fix

Add a useEffect in Globe/index.tsx that holds a CesiumComponentRef to the underlying Cesium Globe object. Once providerPromise resolves, it directly sets globe.terrainProvider on the Cesium element, bypassing Resium's update() timing entirely.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an initial-mount timing gap where Resium may skip applying terrainProvider to the Cesium Globe when terrain is already enabled at mount time (e.g., navigation-back with synchronous Apollo cache data), leaving the globe stuck on the default EllipsoidTerrainProvider.

Changes:

  • Introduces a direct CesiumComponentRef to access the underlying Cesium Globe instance.
  • Adds an effect that, once the terrain provider promise resolves, assigns globe.terrainProvider directly to bypass Resium’s initial update() gating.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ZTongci
ZTongci marked this pull request as ready for review June 24, 2026 03:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/engines/Cesium/core/Globe/index.tsx Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@bnimit bnimit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ZTongci
ZTongci merged commit 732d7bd into alpha Jun 24, 2026
2 of 3 checks passed
@ZTongci
ZTongci deleted the fix/globe-terrain-provider-on-mount branch June 24, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants