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

[v9] experiment: rework reconciler architecture, create objects on commit

Open CodyJasonBennett opened this issue 3 years ago • 1 comments
trafficstars

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 commitMount and container instances with react. #2268 should have been sufficient to fix #2250, but useLayoutEffect fires before container instances are committed. This affects portals in this PR and is the reason behind the usage of <primitive object={scene} /> in root#render and the omission of container reconciler hooks.

CodyJasonBennett avatar Jul 21 '22 15:07 CodyJasonBennett

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

codesandbox-ci[bot] avatar Jul 21 '22 15:07 codesandbox-ci[bot]

Continued in #2465, dropping architecture changes.

CodyJasonBennett avatar Aug 27 '22 16:08 CodyJasonBennett