Skip to content

Commit

Permalink
fix: invalidate pierced props (#2549)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Oct 11, 2022
1 parent 68abd48 commit accff84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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')
})
})

0 comments on commit accff84

Please sign in to comment.