1+ import { type Globe as CesiumGlobeType } from "cesium" ;
12import { useEffect , useMemo , useRef , type JSX } from "react" ;
2- import { Globe as CesiumGlobe } from "resium" ;
3+ import { Globe as CesiumGlobe , type CesiumComponentRef } from "resium" ;
34
45import type { ViewerProperty } from "../../.." ;
56import { toColor } from "../../common" ;
@@ -31,8 +32,30 @@ export default function Globe({
3132 [ property ?. globe ?. baseColor ] ,
3233 ) ;
3334
34- const lastResolvedProviderRef = useRef < any > ( null ) ;
35+ // Direct ref to the underlying Cesium Globe object.
36+ // Resium's Globe.update() is skipped on initial mount when C.current=false
37+ // (a Resium timing issue). This effect guarantees globe.terrainProvider is
38+ // always applied once the Promise resolves, regardless of prop-change timing.
39+ const cesiumGlobeRef = useRef < CesiumComponentRef < CesiumGlobeType > > ( null ) ;
40+ useEffect ( ( ) => {
41+ let cancelled = false ;
42+ providerPromise
43+ . then ( resolvedProvider => {
44+ if ( cancelled ) return ;
45+ const cesiumGlobe = cesiumGlobeRef . current ?. cesiumElement ;
46+ if ( cesiumGlobe ) {
47+ cesiumGlobe . terrainProvider = resolvedProvider ;
48+ }
49+ } )
50+ . catch ( ( ) => {
51+ // provider errors are handled by the existing useEffect below
52+ } ) ;
53+ return ( ) => {
54+ cancelled = true ;
55+ } ;
56+ } , [ providerPromise ] ) ;
3557
58+ const lastResolvedProviderRef = useRef < Awaited < typeof providerPromise > | null > ( null ) ;
3659 useEffect ( ( ) => {
3760 let isCancelled = false ;
3861
@@ -55,6 +78,7 @@ export default function Globe({
5578
5679 return (
5780 < CesiumGlobe
81+ ref = { cesiumGlobeRef }
5882 baseColor = { baseColor }
5983 enableLighting = { ! ! property ?. globe ?. enableLighting }
6084 showGroundAtmosphere = { property ?. globe ?. atmosphere ?. enabled ?? true }
0 commit comments