react-three-fiber
react-three-fiber copied to clipboard
[v9] experiment: rework reconciler architecture, create objects on commit
Fixes #2250 and a host of other issues when mutating a three.js object as an internal instance by separating the two and delegating three.js object creation until commit mount. This mitigates side-effects from creating objects and mutating them since the tree is now finalized and connected via instance descriptors.
An instance now looks like this, with object being the underlying three.js object and object.__r3f referring to its respective Instance:
interface Instance {
root: UseBoundStore<RootState>
type: string
parent: Instance | null
children: Instance[]
props: InstanceProps
object: any | null
eventCount: number
handlers: Partial<EventHandlers>
attach?: AttachType
previousAttach?: any
}
Notably, objects was renamed children and is used for all instances, regardless of the use of attach. memoizedProps is now props and indiscriminately contains elements' props.
Note: I'm keeping this as a draft until I clarify the behavior of
commitMountand container instances with react. #2268 should have been sufficient to fix #2250, butuseLayoutEffectfires before container instances are committed. This affects portals in this PR and is the reason behind the usage of<primitive object={scene} />inroot#renderand the omission of container reconciler hooks.
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 5b3a2378c2608580ffa386622f770be375387334:
| Sandbox | Source |
|---|---|
| example | Configuration |
| append-bug | Issue #2250 |
Continued in #2465, dropping architecture changes.