Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e7a1025
experiment: separate instance & object, create objects on commit
CodyJasonBennett Jul 21, 2022
7eccdc0
fix(detach): overwrite target
CodyJasonBennett Jul 21, 2022
30b3227
fix(renderer): add back removerecursive
CodyJasonBennett Jul 21, 2022
ee03b1d
fix(renderer): safely check objects when hiding/suspense
CodyJasonBennett Jul 21, 2022
5e97a14
fix(applyProps): use target args on HMR copy
CodyJasonBennett Jul 21, 2022
ebced55
fix(diffProps): filter reserved keys
CodyJasonBennett Jul 21, 2022
8334dad
refactor: cleanup prop diffing
CodyJasonBennett Jul 21, 2022
4f3da21
refactor(RTTR): use new instance structure, cleanup internal types
CodyJasonBennett Jul 21, 2022
3aea5b2
fix: safely add object3ds on commit
CodyJasonBennett Jul 22, 2022
ae3c219
fix(renderer): update instance on commitupdate, cleanup prop filter
CodyJasonBennett Jul 22, 2022
67ecde9
fix: safely check container parents, de-dup interaction on commit
CodyJasonBennett Jul 22, 2022
7dec566
fix(RTTR): correctly traverse root react element
CodyJasonBennett Jul 22, 2022
58d656f
chore(tests): update instance snapshot
CodyJasonBennett Jul 22, 2022
9ab0eb7
chore(RTTR): make sure fireEvent warns on invalid prop
CodyJasonBennett Jul 22, 2022
0720009
fix(renderer): safely append to container
CodyJasonBennett Jul 22, 2022
c112c8d
fix(renderer): loosen commit append to parents
CodyJasonBennett Jul 22, 2022
f43e768
fix(renderer): de-ref oldinstance after swap
CodyJasonBennett Jul 22, 2022
656d11b
fix(RTTR): don't use internal container methods
CodyJasonBennett Jul 22, 2022
f2db2f9
refactor(RTTR): cleanup fiber traversal
CodyJasonBennett Jul 22, 2022
d5fb4a7
chore(types): don't export internal props
CodyJasonBennett Jul 22, 2022
975a2ba
fix: hide non-renderable objects on suspend
CodyJasonBennett Jul 22, 2022
c5f1793
Merge branch 'master' into experiment/commit-architecture
CodyJasonBennett Jul 22, 2022
775e485
Merge branch 'v9' into experiment/commit-architecture
CodyJasonBennett Jul 25, 2022
191a4fc
fix(renderer): always attach instance localstate
CodyJasonBennett Jul 29, 2022
08ac484
Merge branch 'v9' into experiment/commit-architecture
CodyJasonBennett Jul 29, 2022
35056e8
fix: handle text cases, add coverage
CodyJasonBennett Jul 30, 2022
ef8c6a2
Merge branch 'v9' into experiment/commit-architecture
CodyJasonBennett Aug 4, 2022
d5402e0
chore: fix conflicts
CodyJasonBennett Aug 4, 2022
59a3aef
chore: lint
CodyJasonBennett Aug 4, 2022
50a1fad
experiment: add suspense boundaries to portals example
CodyJasonBennett Aug 4, 2022
31927b6
Merge branch 'v9' into experiment/commit-architecture
CodyJasonBennett Aug 20, 2022
ac63742
experiment: commit on finalizeInitialChildren
CodyJasonBennett Aug 20, 2022
eabc13b
fix: revert commit on finalizeInitialChildren
CodyJasonBennett Aug 20, 2022
0614a16
Merge branch 'v9' into experiment/commit-architecture
CodyJasonBennett Aug 21, 2022
5b3a237
Merge branch 'v9' into experiment/commit-architecture
CodyJasonBennett Aug 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions packages/fiber/src/core/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function createEvents(store: UseBoundStore<RootState>) {
function filterPointerEvents(objects: THREE.Object3D[]) {
return objects.filter((obj) =>
['Move', 'Over', 'Enter', 'Out', 'Leave'].some(
(name) => (obj as unknown as Instance).__r3f?.handlers[('onPointer' + name) as keyof EventHandlers],
(name) => ((obj as any).__r3f as Instance)?.handlers[('onPointer' + name) as keyof EventHandlers],
),
)
}
Expand Down Expand Up @@ -239,7 +239,7 @@ export function createEvents(store: UseBoundStore<RootState>) {
let eventObject: THREE.Object3D | null = hit.object
// Bubble event up
while (eventObject) {
if ((eventObject as unknown as Instance).__r3f?.eventCount) intersections.push({ ...hit, eventObject })
if (((eventObject as any).__r3f as Instance)?.eventCount) intersections.push({ ...hit, eventObject })
eventObject = eventObject.parent
}
}
Expand Down Expand Up @@ -369,7 +369,7 @@ export function createEvents(store: UseBoundStore<RootState>) {
)
) {
const eventObject = hoveredObj.eventObject
const instance = (eventObject as unknown as Instance).__r3f
const instance = (eventObject as any).__r3f as Instance
const handlers = instance?.handlers
internal.hovered.delete(makeId(hoveredObj))
if (instance?.eventCount) {
Expand Down Expand Up @@ -434,7 +434,7 @@ export function createEvents(store: UseBoundStore<RootState>) {

handleIntersects(hits, event, delta, (data: ThreeEvent<DomEvent>) => {
const eventObject = data.eventObject
const instance = (eventObject as unknown as Instance).__r3f
const instance = (eventObject as any).__r3f as Instance
const handlers = instance?.handlers
// Check presence of handlers
if (!instance?.eventCount) return
Expand Down Expand Up @@ -487,9 +487,7 @@ export function createEvents(store: UseBoundStore<RootState>) {
}

function pointerMissed(event: MouseEvent, objects: THREE.Object3D[]) {
objects.forEach((object: THREE.Object3D) =>
(object as unknown as Instance).__r3f?.handlers.onPointerMissed?.(event),
)
objects.forEach((object: THREE.Object3D) => ((object as any).__r3f as Instance)?.handlers.onPointerMissed?.(event))
}

return { handlePointer }
Expand Down
17 changes: 14 additions & 3 deletions packages/fiber/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
updateCamera,
setDeep,
} from './utils'
import { useStore } from './hooks'
import { useStore, useThree } from './hooks'

const roots = new Map<Element, Root>()
const { invalidate, advance } = createLoop(roots)
Expand Down Expand Up @@ -332,6 +332,11 @@ function render<TCanvas extends Element>(
return root.render(children)
}

function Scene({ children }: { children: React.ReactNode }) {
const scene = useThree((state) => state.scene)
return <primitive object={scene}>{children}</primitive>
}

function Provider<TElement extends Element>({
store,
children,
Expand All @@ -355,7 +360,11 @@ function Provider<TElement extends Element>({
if (!store.getState().events.connected) state.events.connect?.(rootElement)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return <context.Provider value={store}>{children}</context.Provider>
return (
<context.Provider value={store}>
<Scene>{children}</Scene>
</context.Provider>
)
}

function unmountComponentAtNode<TElement extends Element>(canvas: TElement, callback?: (canvas: TElement) => void) {
Expand Down Expand Up @@ -506,7 +515,9 @@ function Portal({
return (
<>
{reconciler.createPortal(
<context.Provider value={usePortalStore}>{children}</context.Provider>,
<context.Provider value={usePortalStore}>
<Scene>{children}</Scene>
</context.Provider>,
usePortalStore,
null,
)}
Expand Down
Loading