Skip to content

Commit

Permalink
fix: invalidate pierced props
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Oct 11, 2022
1 parent 968891b commit 3135851
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/fiber/src/core/utils.ts
Expand Up @@ -260,6 +260,11 @@ export function diffProps<T = any>(

// Props changed, add them
changedProps[prop] = newProps[prop]

// Reset pierced props
for (const other in newProps) {
if (other.startsWith(`${prop}-`)) changedProps[other] = newProps[other]
}
}

// Reset removed props for HMR
Expand Down
12 changes: 12 additions & 0 deletions packages/fiber/tests/utils.test.ts
Expand Up @@ -262,6 +262,18 @@ describe('diffProps', () => {
expect(filtered).toStrictEqual({ bar: false })
})

it('invalidates pierced props when root is changed', async () => {
const texture1 = { needsUpdate: false, name: '' } as THREE.Texture
const texture2 = { needsUpdate: false, name: '' } as THREE.Texture

const oldProps = { map: texture1, 'map-needsUpdate': true, 'map-name': 'test' }
const newProps = { map: texture2, 'map-needsUpdate': true, 'map-name': 'test' }

const instance = prepare({}, storeMock, '', oldProps)
const filtered = diffProps(instance, newProps)
expect(filtered).toStrictEqual(newProps)
})

it('should pick removed props for HMR', () => {
const instance = prepare(new THREE.Object3D(), storeMock, '', { position: [0, 0, 1] })
const newProps = {}
Expand Down

0 comments on commit 3135851

Please sign in to comment.