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: invalidate pierced props #2549

Merged
merged 3 commits 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
6 changes: 6 additions & 0 deletions packages/fiber/src/core/utils.ts
Expand Up @@ -233,6 +233,12 @@ export function diffProps(
let entries: string[] = []
if (key.includes('-')) entries = key.split('-')
changes.push([key, value, false, entries])

// Reset pierced props
for (const prop in props) {
const value = props[prop]
if (prop.startsWith(`${key}-`)) changes.push([prop, value, false, prop.split('-')])
}
})

const memoized: { [key: string]: any } = { ...props }
Expand Down
22 changes: 22 additions & 0 deletions packages/fiber/tests/core/renderer.test.tsx
Expand Up @@ -762,4 +762,26 @@ describe('renderer', () => {
expect(groupHandle).toBeDefined()
expect(prevUUID).not.toBe(groupHandle!.uuid)
})

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

await act(async () =>
root.render(<meshBasicMaterial ref={material} map={texture1} map-needsUpdate={true} map-name="test" />),
)

expect(material.current!.map).toBe(texture1)
expect(texture1.needsUpdate).toBe(true)
expect(texture1.name).toBe('test')

await act(async () =>
root.render(<meshBasicMaterial ref={material} map={texture2} map-needsUpdate={true} map-name="test" />),
)

expect(material.current!.map).toBe(texture2)
expect(texture2.needsUpdate).toBe(true)
expect(texture2.name).toBe('test')
})
})