Skip to content

Commit 7c6680f

Browse files
committed
feat: add explicit error to applyProps
1 parent cef370b commit 7c6680f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/fiber/src/core/utils.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ export function applyProps<T = any>(object: Instance<T>['object'], props: Instan
424424

425425
let { root, key, target } = resolve(object, prop)
426426

427+
// Throw an error if we attempted to set a pierced prop to a non-object
428+
if (target === undefined && (typeof root !== 'object' || root === null)) {
429+
throw Error(`R3F: Cannot set "${prop}". Ensure it is an object before setting "${key}".`)
430+
}
431+
427432
// Layers must be written to the mask property
428433
if (target instanceof THREE.Layers && value instanceof THREE.Layers) {
429434
target.mask = value.mask

packages/fiber/tests/utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ describe('applyProps', () => {
372372
const target = new THREE.Object3D()
373373
applyProps(target, {})
374374
expect(() => applyProps(target, { ['foo-bar']: 1 })).not.toThrow()
375+
expect((target as any)['foo-bar']).toBe(undefined)
375376
})
376377

377378
it('should throw when applying unknown props due to non-object intermediate', () => {

0 commit comments

Comments
 (0)