Skip to content

Commit

Permalink
Revert "experiment: stable object sort (#3066)" (#3069)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett authored Oct 26, 2023
1 parent 4c06baa commit 199edfe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
26 changes: 7 additions & 19 deletions packages/fiber/src/core/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?:
added = true
}

const objects = parentInstance.__r3f?.objects
if (!added && objects) {
const index = objects.indexOf(beforeChild)
if (index !== -1) objects.splice(index, 0, child)
else objects.push(child)
}

if (!added) parentInstance.__r3f?.objects.push(child)
if (!child.__r3f) prepare(child, {})
child.__r3f.parent = parentInstance
updateInstance(child)
Expand All @@ -195,11 +189,8 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?:
// Clear the parent reference
if (child.__r3f) child.__r3f.parent = null
// Remove child from the parents objects
const objects = parentInstance.__r3f?.objects
if (objects) {
const index = objects.indexOf(child)
if (index !== -1) objects.splice(index, 1)
}
if (parentInstance.__r3f?.objects)
parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter((x) => x !== child)
// Remove attachment
if (child.__r3f?.attach) {
detach(parentInstance, child, child.__r3f.attach)
Expand Down Expand Up @@ -272,16 +263,13 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?:
instance.__r3f.objects.forEach((child) => appendChild(newInstance, child))
instance.__r3f.objects = []

const autoRemovedBeforeAppend = !!newInstance.parent

if (!instance.__r3f.autoRemovedBeforeAppend) {
insertBefore(parent, newInstance, instance)
removeChild(parent, instance)
} else {
appendChild(parent, newInstance)
}

newInstance.__r3f.autoRemovedBeforeAppend = autoRemovedBeforeAppend
if (newInstance.parent) {
newInstance.__r3f.autoRemovedBeforeAppend = true
}
appendChild(parent, newInstance)

// Re-bind event handlers
if (newInstance.raycast && newInstance.__r3f.eventCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,19 @@ Array [
Object {
"children": Array [],
"props": Object {
"args": Array [
2,
2,
],
"args": Array [],
},
"type": "boxGeometry",
"type": "meshBasicMaterial",
},
Object {
"children": Array [],
"props": Object {
"args": Array [],
"args": Array [
2,
2,
],
},
"type": "meshBasicMaterial",
"type": "boxGeometry",
},
],
"props": Object {
Expand Down

0 comments on commit 199edfe

Please sign in to comment.