@dcl/react-ecs 7.21.1-22918726402.commit-ee210ee → 7.21.1-23203004012.commit-7c64ac2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -156,11 +156,15 @@ export function createReconciler(engine, pointerEvents) {
156
156
  const rightOfChild = parent._child.find((c) => c.rightOf === child.entity);
157
157
  if (rightOfChild) {
158
158
  rightOfChild.rightOf = child.rightOf;
159
- // Re-order parent._child array
160
- parent._child = parent._child.filter((c) => c.entity !== child.entity);
161
- parent._child.push(child);
162
159
  updateTree(rightOfChild, { rightOf: rightOfChild.rightOf });
163
160
  }
161
+ // Always remove from old position and push to end for reorders.
162
+ // Previously, filter/push was inside the if(rightOfChild) block, so when
163
+ // rightOfChild was not found (child was last), the child stayed at its old
164
+ // position. This caused _child[length-2] to potentially be the child itself,
165
+ // producing a self-referencing rightOf.
166
+ parent._child = parent._child.filter((c) => c.entity !== child.entity);
167
+ parent._child.push(child);
164
168
  // Its a re-order. We are the last element, so we need to fetch the element before us.
165
169
  child.rightOf = parent._child[parent._child.length - 2]?.entity;
166
170
  }
@@ -174,13 +178,14 @@ export function createReconciler(engine, pointerEvents) {
174
178
  }
175
179
  function removeChild(parentInstance, child) {
176
180
  const childIndex = parentInstance._child.findIndex((c) => c.entity === child.entity);
177
- const childToModify = parentInstance._child[childIndex + 1];
178
- if (childToModify) {
179
- childToModify.rightOf = child.rightOf;
180
- updateTree(childToModify, { rightOf: child.rightOf });
181
+ if (childIndex !== -1) {
182
+ const childToModify = parentInstance._child[childIndex + 1];
183
+ if (childToModify) {
184
+ childToModify.rightOf = child.rightOf;
185
+ updateTree(childToModify, { rightOf: child.rightOf });
186
+ }
187
+ parentInstance._child.splice(childIndex, 1);
181
188
  }
182
- // Mutate 💀
183
- parentInstance._child.splice(childIndex, 1);
184
189
  removeChildEntity(child);
185
190
  }
186
191
  function updateOnChange(entity, componentId, state) {
@@ -258,6 +263,23 @@ export function createReconciler(engine, pointerEvents) {
258
263
  }
259
264
  },
260
265
  insertBefore(parentInstance, child, beforeChild) {
266
+ // Handle reorder: if child already exists in this parent, remove it from its old position
267
+ // and fix up the old neighbor's rightOf before inserting at the new position.
268
+ const existingIndex = parentInstance._child.findIndex((c) => c.entity === child.entity);
269
+ if (existingIndex !== -1) {
270
+ // If beforeChild.rightOf already points to child, child is already in the correct
271
+ // position in the rightOf chain. Setting child.rightOf = beforeChild.rightOf would
272
+ // produce a self-cycle (child.rightOf = child.entity).
273
+ if (beforeChild.rightOf === child.entity) {
274
+ return;
275
+ }
276
+ const oldNextSibling = parentInstance._child[existingIndex + 1];
277
+ if (oldNextSibling) {
278
+ oldNextSibling.rightOf = child.rightOf;
279
+ updateTree(oldNextSibling, { rightOf: oldNextSibling.rightOf });
280
+ }
281
+ parentInstance._child.splice(existingIndex, 1);
282
+ }
261
283
  const beforeChildIndex = parentInstance._child.findIndex((c) => c.entity === beforeChild.entity);
262
284
  parentInstance._child = [
263
285
  ...parentInstance._child.slice(0, beforeChildIndex),
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dcl/react-ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.21.1-22918726402.commit-ee210ee",
4
+ "version": "7.21.1-23203004012.commit-7c64ac2",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
7
7
  "dependencies": {
8
- "@dcl/ecs": "7.21.1-22918726402.commit-ee210ee",
8
+ "@dcl/ecs": "7.21.1-23203004012.commit-7c64ac2",
9
9
  "react": "^18.2.0",
10
10
  "react-reconciler": "^0.29.0"
11
11
  },
@@ -40,5 +40,5 @@
40
40
  "tsconfig": "./tsconfig.json"
41
41
  },
42
42
  "types": "./dist/index.d.ts",
43
- "commit": "ee210ee78e334e8e696dbae117a8e0019aa13c97"
43
+ "commit": "7c64ac29ee3f34e79019b4435854537a261721ab"
44
44
  }