From 16c82895f18750708b3ac3383b2cabb14a7fdd5a Mon Sep 17 00:00:00 2001 From: Cody Bennett Date: Thu, 9 Jan 2025 02:42:41 -0600 Subject: [PATCH] fix: loosen instanceof checks for CSB issue (#3426) --- packages/fiber/src/core/index.tsx | 4 ++-- packages/fiber/src/core/renderer.ts | 4 ++-- packages/fiber/src/core/store.ts | 4 ++-- packages/fiber/src/core/utils.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/fiber/src/core/index.tsx b/packages/fiber/src/core/index.tsx index ebf8c91fb3..bce6f0f859 100644 --- a/packages/fiber/src/core/index.tsx +++ b/packages/fiber/src/core/index.tsx @@ -255,8 +255,8 @@ function createRoot(canvas: TCanvas): ReconcilerRoot(_roots: Map, _getEventPriority?: // Auto-attach geometries and materials if (instance.__r3f.attach === undefined) { - if (instance instanceof THREE.BufferGeometry) instance.__r3f.attach = 'geometry' - else if (instance instanceof THREE.Material) instance.__r3f.attach = 'material' + if ((instance as unknown as THREE.BufferGeometry).isBufferGeometry) instance.__r3f.attach = 'geometry' + else if ((instance as unknown as THREE.Material).isMaterial) instance.__r3f.attach = 'material' } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the diff --git a/packages/fiber/src/core/store.ts b/packages/fiber/src/core/store.ts index 1c1b92c7d7..a0cc0fd139 100644 --- a/packages/fiber/src/core/store.ts +++ b/packages/fiber/src/core/store.ts @@ -177,8 +177,8 @@ const createStore = (invalidate: Invalidate, advance: Advance): UseBoundStore { const { width, height, top, left } = size const aspect = width / height - if (target instanceof THREE.Vector3) tempTarget.copy(target) - else tempTarget.set(...target) + if ((target as THREE.Vector3).isVector3) tempTarget.copy(target as THREE.Vector3) + else tempTarget.set(...(target as Parameters)) const distance = camera.getWorldPosition(position).distanceTo(tempTarget) if (isOrthographicCamera(camera)) { return { width: width / camera.zoom, height: height / camera.zoom, top, left, factor: 1, distance, aspect } diff --git a/packages/fiber/src/core/utils.ts b/packages/fiber/src/core/utils.ts index 2fb941d255..22fb730e74 100644 --- a/packages/fiber/src/core/utils.ts +++ b/packages/fiber/src/core/utils.ts @@ -396,7 +396,7 @@ export function applyProps(instance: MaybeInstance, data: InstanceProps | DiffSe // If nothing else fits, just set the single value, ignore undefined // https://github.com/pmndrs/react-three-fiber/issues/274 else if (value !== undefined) { - const isColor = targetProp instanceof THREE.Color + const isColor = (targetProp as unknown as THREE.Color | undefined)?.isColor // Allow setting array scalars if (!isColor && targetProp.setScalar) targetProp.setScalar(value) // Layers have no copy function, we must therefore copy the mask property @@ -415,7 +415,7 @@ export function applyProps(instance: MaybeInstance, data: InstanceProps | DiffSe // Auto-convert sRGB textures, for now ... // https://github.com/pmndrs/react-three-fiber/issues/344 if ( - currentInstance[key] instanceof THREE.Texture && + (currentInstance[key] as unknown as THREE.Texture | undefined)?.isTexture && // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129 currentInstance[key].format === THREE.RGBAFormat && currentInstance[key].type === THREE.UnsignedByteType &&