Repository navigation
fix(octane): remove a .tsx Provider's children when they become null - #2076
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | 745bf80 | Commit Preview URL Branch Preview URL |
Oct 15 2026, 10:20 AM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | 745bf80 | Commit Preview URL Branch Preview URL |
Oct 15 2026, 10:21 AM |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Null CompiledContext breaks transition rollback
- resetScopeChildren now journals the child records it replaces, so a discarded render restores them with the child DOM and the next render updates that subtree instead of mounting a second copy.
Or push these changes by commenting:
@cursor push 45710c7dce
Preview (45710c7dce)
diff --git a/.changeset/compiled-context-discarded-clear.md b/.changeset/compiled-context-discarded-clear.md
new file mode 100644
--- /dev/null
+++ b/.changeset/compiled-context-discarded-clear.md
@@ -1,0 +1,5 @@
+---
+"octane": patch
+---
+
+Keep a `CompiledContext`'s children when a render that clears them is discarded. The following render updates those children instead of mounting a second copy beside the restored ones.
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -16976,6 +16976,16 @@
// Drop the collections rather than emptying them: the lazily-allocated ones go back to null,
// and `slots` gets a fresh array (compiled bodies index it directly, so it stays non-null).
+ // A discarded root render restores the child DOM detached above. Journal the records
+ // replaced below with it, so that DOM still belongs to the scope that rendered it.
+ journalRootProperty(scope, 'children', scope.children);
+ journalRootProperty(scope, 'cleanups', scope.cleanups);
+ journalRootProperty(scope, '_slots', scope._slots);
+ journalRootProperty(scope, 'effectSlots', scope.effectSlots);
+ journalRootProperty(scope, 'hooks', scope.hooks);
+ journalRootProperty(scope, 'slots', scope.slots);
+ journalRootProperty(scope, 'compilerMemo', scope.compilerMemo);
+ journalRootProperty(scope, 'refFields', scope.refFields);
scope.children = null;
scope.cleanups = null;
scope._slots = null;
diff --git a/packages/octane/tests/_fixtures/compiled-boundaries.tsrx b/packages/octane/tests/_fixtures/compiled-boundaries.tsrx
--- a/packages/octane/tests/_fixtures/compiled-boundaries.tsrx
+++ b/packages/octane/tests/_fixtures/compiled-boundaries.tsrx
@@ -3,6 +3,7 @@
CompiledOutlet,
createCompiledContext,
createContext,
+ use,
useContext,
useLayoutEffect,
useState,
@@ -98,6 +99,25 @@
</main>
}
+function Hold(props: { gate: PromiseLike<string> | null }) @{
+ const value = props.gate !== null ? use(props.gate) : 'held';
+ <span>{value as string}</span>
+}
+
+export function SuspendedGateShell(props: {
+ show: boolean;
+ gate: PromiseLike<string> | null;
+ log: (message: string) => void;
+}) @{
+ <main>
+ <GateProvider show={props.show}>
+ <Screen label="screen" log={props.log} />
+ </GateProvider>
+ <Hold gate={props.gate} />
+ <footer>tail</footer>
+ </main>
+}
+
export function PendingShell(props: { component: typeof Other; label: string }) @{
<CompiledContext context={Tone} value="ready">
@try {
diff --git a/packages/octane/tests/compiled-boundaries.test.ts b/packages/octane/tests/compiled-boundaries.test.ts
--- a/packages/octane/tests/compiled-boundaries.test.ts
+++ b/packages/octane/tests/compiled-boundaries.test.ts
@@ -119,6 +119,43 @@
expect(() => renderToString(server.CheckedProvider, props)).toThrow(/CompiledContext/);
});
+ it('keeps compiled provider children when a render that clears them is discarded', () => {
+ const events: string[] = [];
+ const log = (value: string) => events.push(value);
+ const view = mount(client.SuspendedGateShell, { show: true, gate: null, log });
+ try {
+ const button = view.container.querySelector('button')!;
+ const article = view.container.querySelector('article')!;
+ flushSync(() => button.click());
+ expect(button.textContent).toBe('screen:gated:1');
+
+ // A later sibling suspends the root, so this clear never commits.
+ const gate = new Promise<string>(() => {});
+ flushSync(() => view.root.render(client.SuspendedGateShell, { show: false, gate, log }));
+ expect(view.container.querySelector('article')).toBe(article);
+ expect(view.container.querySelectorAll('button')).toHaveLength(1);
+ expect(button.textContent).toBe('screen:gated:1');
+ expect(view.container.querySelector('footer')!.textContent).toBe('tail');
+ expect(events).toEqual(['mount']);
+
+ flushSync(() => view.root.render(client.SuspendedGateShell, { show: true, gate: null, log }));
+ expect(view.container.querySelectorAll('article')).toHaveLength(1);
+ expect(view.container.querySelector('article')).toBe(article);
+ expect(view.container.querySelector('button')).toBe(button);
+ expect(button.textContent).toBe('screen:gated:1');
+ expect(events).toEqual(['mount']);
+
+ flushSync(() =>
+ view.root.render(client.SuspendedGateShell, { show: false, gate: null, log }),
+ );
+ expect(view.container.querySelector('article')).toBeNull();
+ expect(view.container.querySelector('footer')!.textContent).toBe('tail');
+ expect(events).toEqual(['mount', 'cleanup']);
+ } finally {
+ view.unmount();
+ }
+ });
+
it('removes compiled provider children when they become null', () => {
const events: string[] = [];
const log = (value: string) => events.push(value);You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 7c4b792. Configure here.
…transition can't duplicate its children
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
70 other measured values are unchanged. Public-import reachability bundles (bytes)
108 other measured values are unchanged. |
* fix(octane): remove a .tsx Provider's children when they become null (#2076) * fix(octane): remove a .tsx Provider's children when they become null * fix(octane): remove CompiledContext children when they become null * fix(octane): keep CompiledContext's emptied dialect so a rolled-back transition can't duplicate its children * test(website): reload the dev /devtools warm-up once before failing Main a9dfdf7 failed the website integration suite: the dev-SSR beforeAll waited 120 s for the TanStack Devtools trigger on /devtools and skipped all 37 dev-SSR tests. The wait came with #2062 and has failed on main and two branches since, while passing locally on every cold warm-up (~3.9 s). The devtools client mounts after hydration from modules a cold dev server may only discover on that first visit, and Vite recovers with a reload a slow runner can miss. Wait 60 s, log what the first attempt saw, reload once, and fail with the page errors if the trigger still never appears. The devtools tests themselves still assert the trigger and panel on fresh loads. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(three): render Canvas as a Strong template (#2080) * fix(octane): seed nothing for a pending snapshot read instead of throwing (#2077) A server module that reads module signals installs the native read collector as it loads, and every later render in the process then collects its reads for the hydration snapshot. A render that read a pending query through snapshot(), such as an automatically streamed query, completed with a read it could not seed and threw "A completed native server read has no serializable ready value". On main 0bb503f, 28 of the 30 early-independent-intent cases throw once that collector exists, while the same page renders in a server that has loaded no such module. A snapshot renders a pending or failed state as it is, without suspending. The client resolves that state itself, or takes a stream's later delivery, so the read now contributes no seed, which is also no invented ready one. A completed value read of an unready source still throws. The signals-hydration case that pinned the throw now asserts that contract: the pending output renders with no hydration snapshot, adopts the same node, and shows the result once the query resolves. The supplemental native DOM smoke case says the same. The new streamed test loads a module-signal page, renders a pending snapshot under streamed signals, hydrates while the client is still pending, and takes the stream's result without a second fetch. Co-authored-by: Claude Opus 5.5 <[email protected]> * fix(octane): render a server element entry as its component's root, as hydrateRoot does (#2078) * fix(octane): render a server element entry as its component's root, as hydrateRoot does renderToString(<App />), and every other server renderer given an element, rendered the element as a value its root returns (renderEntryValue), which frames the component in a range of its own. hydrateRoot(container, <App />) unwraps an element whose type is a component into the root's body and props, as it does App itself, so the client root has no such range. When App returns a component, a fragment, a Suspense boundary or a template, or renders its children, the server's HTML did not match, and the root rendered on the client with a recoverable error. Each server renderer now reads its entry through renderEntry: a component element renders as that component's root, with the props its descriptor renders it with (descriptorProps, shared with ssrComponentDescriptor), and any other value as before. The two entry forms produce the same HTML, and either hydrates through either hydrateRoot form. root-entry-forms pins every pairing of renderToString and renderToReadableStream, each given App or <App />, with hydrateRoot given App or <App />, for a root that returns host JSX, a template, a component, a fragment, text, null, a Suspense boundary or its children, in dev and prod compiles: 80 of its 256 cases fail before this change. Client bundles are unchanged; the minified server runtime shrinks 234 B raw. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): read a server descriptor's children only after the scoped check A scoped component descriptor's children getter resolves deferred children, so reading it first ran them in the parent's scope before the component entered. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> * test(website): let the generated MDX hot-update test re-write and outwait a slow runner Main 8318702 failed the website integration suite: "hot-updates generated MDX twice while preserving the surrounding interactive page" timed out waiting 20 s for an edit to reach the page. It also failed on perf/runtime-size-redesign; it passes locally every time. Until 1622fa0 the /devtools warm-up flake skipped the whole dev-SSR block, which hid it. Each edit now waits in 15 s rounds, re-writing the file between rounds in case the watcher dropped a write that followed the previous one, for up to 60 s; the test's budget grows to 180 s. The assertions are unchanged: the generated text updates, the sibling counter keeps its state, and no errors. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): keep an emptied Provider's dialect, and refill it through a frontier (#2043) Clearing an emptied CompiledContext at commit dropped its hooks map, so the empty dialect was lost; it is now kept. A refill's reset opens the scope's frontier like a dialect flip, so its incoming body builds off-document. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Olzhas Alexandrov <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: domgan-oai <[email protected]>


Summary
A
.tsx<Ctx value>Provider, or aCompiledContext, whose children went from a renderable tonullorundefinedkept the previous children mounted. Their DOM stayed on screen, their effects never cleaned up, and their state survived until the Provider rendered children again.Why
renderClientContextProviderandCompiledContextboth returned early onchildren == null, before reconciling slot zero. That is right on the first render, where nothing is mounted yet. After a render with children, though, slot zero still holds their childSlot, and skipping the reconcile leaves it in place.falseand''were not affected: they are not nullish, so they reachedchildSlotand cleared it.We found it in a production app. A sidebar keeps its closing copy mounted until a CSS transition ends, then hides it with
{shown && <Frame />}directly inside a<RenderLocationContext value>. The frame never unmounted. Wrapping the conditional in a fragment worked around it, because the Provider's child is then never nullish..tsrxparents are unaffected. An@ifinside the Provider is part of a compiled children body, which is never nullish. A.tsrxchildren={cond ? body : null}still reaches this path.Changes
runtime.ts:renderClientContextProviderskips the children reconcile only while the Provider has never rendered children, which it already records inCHILDREN_DIALECT_SLOT. Nullish children after that reconcile as a descriptor hole, sochildSlotremoves the previous children. A compiled body followed bynullgoes through the existing dialect flip andresetScopeChildren.runtime.ts:CompiledContextresets its scope on nullish children once it has rendered children, then records the empty dialect2, as the.tsxProvider does. A body arriving over dialect2resets the scope first, so DOM that a rolled-back transition restored is cleared instead of a second copy mounting beside it.jsx-context-childrenfixture and tests: a Provider whose only child switches tonullandundefined, then back. They assert that the child's DOM is gone, its effect cleanup ran, and that showing it again mounts fresh state that still reads the context. A hydration test checks that the server node is adopted without a recoverable error, then removed when the child becomesnull.compiled-boundariesfixture and tests: aCompiledContextwhosechildrenprop switches tonulland back, asserting the child's DOM and cleanup are gone, the sibling after it stays, and the re-shown child has fresh state. A second test empties it inside a transition that suspends, abandons that transition with an urgent re-show, and asserts one copy of the children.octanepatch.Validation
pnpm format:files:checkon the changed filespnpm typecheck: not run as the root script.octane-tsc -p packages/octane/tsconfig.json(coverssrc/) is clean. That config excludestests/, andpnpm typecheck:fileson the test and fixture reports the same missing--jsx/allowImportingTsExtensionserrors onmain, so it can't check.tsxfixtures.pnpm test: not run as the root script.vitest run packages/octaneon the first commit: 48,038/48,074 pass, 36 fail in 8 files, all outside context and Provider code. Rerun on their own, every one of those files passes:behavior-root.test.ts353/353 in two runs,compiler-vite-options.test.ts34/34, the rest together 962/967 then clean, so I read them as load failures. Not rerun in full after theCompiledContextcommit.jsx-context-children.test.tsandcompiled-boundaries.test.tsinoctaneandoctane-prod, 66/66 pass. Withruntime.tsatmain, the new emptying tests fail in both projects. With only the Provider fix, theCompiledContexttest fails. With 7c4b792's runtime, the rollback test fails with two copies of the children.context*,jsx-context*,provider*,linked-state*,hydration/,conformance/context*,transition*,compiled*andlocal-void*inoctaneandoctane-prod: 404 files, 16,953/16,954 pass. The one failure, a 5-second timeout inhydration/descriptor-list-hydrate.test.ts, passes 32/32 rerun alone.perf-review:node scripts/perf-review-scan.mjsreports no candidates. The added check is one optional hook-map read, reached only when a Provider's children are nullish, so the per-render path with children is unchanged.concise-code: +19/−3 lines inruntime.ts, all in the two providers' existing dialect handling. It reuses the dialect slot the Provider already writes instead of adding a field or a second teardown path. I rejected a separatechildren == nullbranch that calledresetScopeChildrenand cleared the slot: it was about 12 lines and duplicated the descriptor path's removal.Risk / follow-ups
''for nullish Provider children, so SSR output does not change.__createCompiledContextkeeps its ownchildren == nullearly return. The compiler uses it only for Providers whose children are written between the tags (private-context.jsrejects achildren=attribute), so its children are never nullish after a render. I left it unchanged.nullinside a transition that suspends is now torn down during render, so if an urgent update abandons the transition and shows it again, it remounts with fresh state. Onmainit kept its state, because the early return left it mounted. The existing compiled-body to.tsx-descriptor flip already behaves this way onmain. A.tsxdescriptor going tonulldefers correctly: the old child stays visible and no cleanup runs until commit.Provenance
agent-authored)Need help on this PR? Tag
@codesmith-botwith what you need.Note
Medium Risk
Touches core Provider reconciliation in
runtime.ts; behavior changes when children go nullish (including transition rollback for compiled bodies), though scoped to Providers and covered by new tests.Overview
Fixes a bug where
.tsx<Context>Providers andCompiledContextkept their previous children mounted whenchildrenswitched tonullorundefined—DOM, effects, and state all lingered until children rendered again.renderClientContextProvidernow still reconciles when children are nullish if the provider has ever rendered children (tracked viaCHILDREN_DIALECT_SLOT), treating that as a descriptor hole so prior children are removed.CompiledContextcallsresetScopeChildrenon nullish children after a prior render, including recording the empty dialect so rolled-back transitions don’t leave duplicate DOM.Adds regression tests for JSX providers (
null/undefined, hydration) and compiledGatedShell(sync unmount, transition abandon). Patch changeset foroctane.Reviewed by Cursor Bugbot for commit 745bf80. Bugbot is set up for automated code reviews on this repo. Configure here.