pmndrs / react-three-fiber

🇨🇭 A React renderer for Three.js
https://docs.pmnd.rs/react-three-fiber
MIT License
27.62k stars 1.6k forks source link

[v9] fix: swap instances in reverse #3272

Closed CodyJasonBennett closed 6 months ago

CodyJasonBennett commented 6 months ago

Refactors switchInstance so we swap instances in reverse, handling tricky cases where we sort or shuffle elements in an array with shared objects. Previously, we had to employ clever tricks since we could only modify instances front-to-back in commitUpdate (the inherent order from React mutation effects). Now, we accumulate instances to be reconstructed in-place, and process them when we hit a tail sibling which is either the last sibling in a view, or the last sibling in a sequence with an update.

codesandbox-ci[bot] commented 6 months ago

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 0e1dec58535cc1861a4d41253ebac9bec3a9d4d0:

Sandbox Source
example Configuration