react-three-fiber
react-three-fiber copied to clipboard
Fixes a bug when reusing primitives in an array.
I added a test for recreating the bug. Maybe there is a nicer method instead of inflating the LocalState.
const primitive1 = new THREE.Mesh()
const primitive2 = new THREE.Mesh()
// Initialize a list of primitives
await act(async () =>
root.render(
<group>
<primitive key={'a'} object={primitive1} name="p1" dispose={null} />
</group>,
),
)
expect(primitive1.__r3f?.type).toBe('primitive')
// New list of primitives while reusing primitive object
await act(async () =>
root.render(
<group>
<primitive key={'b'} object={primitive1} name="p1" dispose={null} />
<primitive key={'c'} object={primitive2} name="p2" dispose={null} />
</group>,
),
)
expect(primitive1.__r3f?.type).toBe('primitive')
expect(primitive2.__r3f?.type).toBe('primitive')
p1 would here be invalid. (__r3f instance got cleared)
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit ebddb72d714cd130fcc1ce0bb4dbdba4667b312b:
| Sandbox | Source |
|---|---|
| example | Configuration |
Sorry, I missed this. Working on bugs surrounding arrays and us swapping elements in-place. We have a few flags already like autoRemovedBeforeAppend which workaround a more fundamental issue I need to track down.
We'll be addressing this in #3248. Thanks for the help.