@@ -95,8 +95,15 @@ const Tileset: FC<PrimitiveProps<Property, any, SceneProperty>> = memo(function
9595 return prevPlanes . current ;
9696 } , [ _planes ] ) ;
9797
98- // Create new clippingPlanes for each tileset to avoid "ClippingPlaneCollection should only be assigned to one object" error
99- // Note: The component remounts on sourceType change due to the key prop, so sourceType is not needed in deps
98+ const tilesetKey =
99+ sourceType === "osm"
100+ ? "osm"
101+ : sourceType === "google-photorealistic"
102+ ? "google"
103+ : tileset ?? "" ;
104+
105+ // Recreate when tilesetKey changes: Cesium destroys the ClippingPlaneCollection
106+ // when its parent Cesium3DTileset is destroyed, so we must not reuse it.
100107 const clippingPlanes = useMemo (
101108 ( ) =>
102109 new CesiumClippingPlaneCollection ( {
@@ -110,7 +117,8 @@ const Tileset: FC<PrimitiveProps<Property, any, SceneProperty>> = memo(function
110117 edgeWidth : edgeWidth ,
111118 edgeColor : toColor ( edgeColor ) ,
112119 } ) ,
113- [ planes , edgeWidth , edgeColor ] ,
120+ // eslint-disable-next-line react-hooks/exhaustive-deps
121+ [ planes , edgeWidth , edgeColor , tilesetKey ] ,
114122 ) ;
115123 const tilesetRef = useRef < Cesium3DTilesetType > ( ) ;
116124
@@ -256,7 +264,7 @@ const Tileset: FC<PrimitiveProps<Property, any, SceneProperty>> = memo(function
256264
257265 return ! isVisible || ( ! tileset && ! sourceType ) || ! tilesetUrl ? null : (
258266 < Cesium3DTileset
259- key = { ` ${ sourceType } - ${ typeof tilesetUrl === "string" ? tilesetUrl : "ion" } ` }
267+ key = { tilesetKey }
260268 ref = { ref }
261269 url = { tilesetUrl }
262270 style = { style }
0 commit comments