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

[v9] fix: invalidate pierced props #2563

Merged
merged 1 commit into from
Oct 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/fiber/src/core/utils.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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