Skip to content

Commit 3a2bef8

Browse files
committed
fix: scan host siblings for scoped placement endAnchor
scopePhysicalPlacement short-circuited on host parents without looking for later out-of-scope siblings, so scoped inserts/reorders under a host with trailing siblings used before:null and landed after them. Scan host children the same way ranges already do, and cover the host-parent case in tests.
1 parent f028dcf commit 3a2bef8

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

‎packages/octane/src/universal-core.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6755,8 +6755,9 @@ class UniversalRootImpl<Container, PublicInstance> implements UniversalRoot<any>
67556755
let endAnchor: number | null = null;
67566756
let current = scope;
67576757
for (let parent = current.parent; parent !== null; current = parent, parent = current.parent) {
6758-
if (parent.kind === 'host') return { parent: parent.id, endAnchor };
6759-
if (parent.kind !== 'range') return null;
6758+
if (parent.kind !== 'host' && parent.kind !== 'range') return null;
6759+
// Host and range parents both keep out-of-scope later siblings; the
6760+
// first physical host after the scope is the append/move fence.
67606761
if (endAnchor === null) {
67616762
const siblings = parent.children;
67626763
for (let index = siblings.indexOf(current) + 1; index < siblings.length; index++) {
@@ -6767,6 +6768,7 @@ class UniversalRootImpl<Container, PublicInstance> implements UniversalRoot<any>
67676768
}
67686769
}
67696770
}
6771+
if (parent.kind === 'host') return { parent: parent.id, endAnchor };
67706772
if (parent === this.rootRecord) return { parent: null, endAnchor };
67716773
}
67726774
return null;

‎packages/octane/tests/universal-event-scope.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,64 @@ describe('universal event scopes', () => {
460460
root.unmount();
461461
});
462462

463+
it('anchors scoped inserts and reorders before later siblings of a host parent', () => {
464+
const container = createObjectContainer();
465+
const root = createUniversalRoot(container, createObjectDriver());
466+
const rowPlan = universalPlan('object', {
467+
kind: 'host',
468+
type: 'row',
469+
bindings: [['label', 0]],
470+
});
471+
const siblingPlan = universalPlan('object', {
472+
kind: 'host',
473+
type: 'sibling',
474+
bindings: [['value', 0]],
475+
});
476+
const viewPlan = universalPlan('object', {
477+
kind: 'host',
478+
type: 'view',
479+
children: [
480+
{ kind: 'slot', slot: 0 },
481+
{ kind: 'slot', slot: 1 },
482+
],
483+
});
484+
let apply!: (ids: string[]) => void;
485+
const Rows = defineUniversalComponent('object', () => {
486+
const [ids, setIds] = useState(['a', 'b'], 'ids');
487+
apply = (next) => setIds(next);
488+
return ids.map((id) => universalValue(rowPlan, [id], id));
489+
});
490+
const Shell = defineUniversalComponent('object', () =>
491+
universalValue(viewPlan, [
492+
universalComponent('object', Rows),
493+
universalValue(siblingPlan, ['sib']),
494+
]),
495+
);
496+
497+
root.render(Shell, undefined);
498+
const view = container.children[0];
499+
expect(view.children.map((child) => child.type)).toEqual(['row', 'row', 'sibling']);
500+
const rowA = view.children[0];
501+
const rowB = view.children[1];
502+
const sibling = view.children[2];
503+
504+
// Host parents own the scope plus later siblings; appends and trailing
505+
// moves must stay before that untouched sibling, not after it.
506+
flushUniversalSync(() => apply(['b', 'a', 'c']));
507+
expect(view.children[0]).toBe(rowB);
508+
expect(view.children[1]).toBe(rowA);
509+
expect(view.children[2].type).toBe('row');
510+
expect(view.children[2].props.label).toBe('c');
511+
const rowC = view.children[2];
512+
expect(view.children[3]).toBe(sibling);
513+
514+
flushUniversalSync(() => apply(['c']));
515+
expect(view.children.map((child) => child.type)).toEqual(['row', 'sibling']);
516+
expect(view.children[0]).toBe(rowC);
517+
expect(view.children[1]).toBe(sibling);
518+
root.unmount();
519+
});
520+
463521
it('updates compact leaf rows from list state without disturbing row identity', () => {
464522
const container = createObjectContainer();
465523
const base = createObjectDriver();

0 commit comments

Comments
 (0)