Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: loosen instanceof checks for CSB issue #3426

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/fiber/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ function createRoot<TCanvas extends Canvas>(canvas: TCanvas): ReconcilerRoot<TCa
if (!state.scene) {
let scene: THREE.Scene

if (sceneOptions instanceof THREE.Scene) {
scene = sceneOptions
if ((sceneOptions as unknown as THREE.Scene | undefined)?.isScene) {
scene = sceneOptions as THREE.Scene
} else {
scene = new THREE.Scene()
if (sceneOptions) applyProps(scene as any, sceneOptions as any)
Expand Down
4 changes: 2 additions & 2 deletions packages/fiber/src/core/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _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
Expand Down
4 changes: 2 additions & 2 deletions packages/fiber/src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ const createStore = (invalidate: Invalidate, advance: Advance): UseBoundStore<Ro
): Omit<Viewport, 'dpr' | 'initialDpr'> {
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<THREE.Vector3['set']>))
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 }
Expand Down
4 changes: 2 additions & 2 deletions packages/fiber/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 &&
Expand Down
Loading