Skip to content

Commit 1f90171

Browse files
committed
fix(octane): open frontier and preserve dialect in emptied CompiledContext remount
clearEmptiedProvider called resetScopeChildren which wiped scope.hooks, losing CHILDREN_DIALECT_SLOT. A later body then saw previous === undefined and mounted as a first render into live DOM, skipping the frontier path. resetProviderChildren also never called openScopeFrontier, so even when the previous === 2 path was reached before commit, the incoming body inserted into the connected parentNode instead of an off-document fragment. Fix both: - clearEmptiedProvider restores CHILDREN_DIALECT_SLOT to 2 after the reset. - resetProviderChildren opens a frontier when live, returning liveEnd. - CompiledContext saves and restores the endMarker around renderSharedBody, matching the descriptor Provider path in renderClientContextProvider.
1 parent 189f545 commit 1f90171

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15649,7 +15649,7 @@ export function createCompiledContext<T>(defaultValue: T): Context<T> {
1564915649
* Clear a Provider scope whose children went away. Over committed DOM the
1565015650
* outgoing children leave at commit, after their cleanups, as a dialect flip's do.
1565115651
*/
15652-
function resetProviderChildren(scope: Scope): void {
15652+
function resetProviderChildren(scope: Scope): Node | null | undefined {
1565315653
const block = scope.block;
1565415654
const parent = block.parentNode;
1565515655
const live = ROOT_RENDER_TRANSACTION !== null && usesFrontier(block, parent);
@@ -15660,12 +15660,18 @@ function resetProviderChildren(scope: Scope): void {
1566015660
block.startMarker !== null ? getNextSibling(block.startMarker) : getFirstChild(parent);
1566115661
if (first !== end)
1566215662
queueRootDeletion(null, first, end === null ? parent.lastChild : end.previousSibling);
15663+
return openScopeFrontier(scope, block, parent);
1566315664
}
1566415665

1566515666
/** A Provider whose children went away clears them once its render commits. */
1566615667
function clearEmptiedProvider(scope: Scope): void {
15667-
if (!scope.block.disposed && scope.hooks?.get(CHILDREN_DIALECT_SLOT) === 2)
15668+
if (!scope.block.disposed && scope.hooks?.get(CHILDREN_DIALECT_SLOT) === 2) {
1566815669
resetScopeChildren(scope);
15670+
// resetScopeChildren wipes the hooks map. Restore the empty dialect so a
15671+
// later body sees previous === 2 and takes the frontier/reset path rather
15672+
// than mounting as a first render into live DOM.
15673+
ensureHooks(scope).set(CHILDREN_DIALECT_SLOT, 2);
15674+
}
1566915675
}
1567015676

1567115677
/** Record a Provider's children dialect; a dropped window restores the previous one. */
@@ -15701,15 +15707,20 @@ export function CompiledContext<T>(
1570115707
}
1570215708
const dialect = (children as any)[CHILDREN_BODY] ?? children;
1570315709
const previous = scope.hooks?.get(CHILDREN_DIALECT_SLOT);
15710+
let liveEnd: Node | null | undefined;
1570415711
if (previous !== dialect) {
1570515712
if (previous === 2) {
15706-
resetProviderChildren(scope);
15713+
liveEnd = resetProviderChildren(scope);
1570715714
if (scope.block.disposed) return;
1570815715
} else if (previous !== undefined) invalidateSharedBodyOutput(scope);
1570915716
setChildrenDialect(scope, previous, dialect);
1571015717
}
15711-
const output = renderSharedBody(children as ComponentBody, undefined, scope, undefined);
15712-
if (output != null) throw new TypeError(formatClientError(345));
15718+
try {
15719+
const output = renderSharedBody(children as ComponentBody, undefined, scope, undefined);
15720+
if (output != null) throw new TypeError(formatClientError(345));
15721+
} finally {
15722+
if (liveEnd !== undefined) scope.block.endMarker = liveEnd;
15723+
}
1571315724
}
1571415725

1571515726
function initializeContext<T>(ctx: Context<T>, defaultValue: T): Context<T> {

0 commit comments

Comments
 (0)