react-three-fiber icon indicating copy to clipboard operation
react-three-fiber copied to clipboard

Fixes a bug when reusing primitives in an array.

Open Inuniku opened this issue 1 year ago • 2 comments

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)

Inuniku avatar Jan 07 '24 00:01 Inuniku

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

codesandbox-ci[bot] avatar Jan 07 '24 00:01 codesandbox-ci[bot]

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.

CodyJasonBennett avatar Apr 26 '24 04:04 CodyJasonBennett

We'll be addressing this in #3248. Thanks for the help.

CodyJasonBennett avatar May 03 '24 17:05 CodyJasonBennett