fix: ensure terrainProvider is applied on initial mount via direct ref - #141
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
CesiumComponentRefto access the underlying CesiumGlobeinstance. - Adds an effect that, once the terrain provider promise resolves, assigns
globe.terrainProviderdirectly to bypass Resium’s initialupdate()gating.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ZTongci
marked this pull request as ready for review
June 24, 2026 03:23
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the
Globecomponent mounts with terrain already enabled — as happens on navigation-back where Apollo cache delivers data synchronously —globe.terrainProvideris never updated from the defaultEllipsoidTerrainProvider. Terrain tiles never load even though theCesiumTerrainProviderPromise resolves correctly.Root Cause
Resium's
useCesiumComponentapplies props (includingterrainProvider) through the component'supdate()function, which is gated behind an internalC.currentflag. That flag is set totrueby a passiveuseEffect. However, the initializerI()runs in a microtask (scheduled fromuseLayoutEffect), which fires before passive effects. SoGlobe.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 afterC.currentis alreadytrue. On navigation-back, Apollo cache delivers scene data synchronously, sosetTimeout(0)fires before the Cesium Viewer has recreated its scene and beforeGlobehas mounted as a React child. Globe mounts with terrain already enabled, no subsequent prop change ever occurs, andglobe.terrainProvideris never set.Fix
Add a
useEffectinGlobe/index.tsxthat holds aCesiumComponentRefto the underlying CesiumGlobeobject. OnceproviderPromiseresolves, it directly setsglobe.terrainProvideron the Cesium element, bypassing Resium'supdate()timing entirely.