Repository navigation
Description
A root-prop transition that changes a useSyncExternalStore selector and suspends leaves the old selection visible, but subsequent notifications consult the pending selector. The displayed selection can therefore stay stale until the suspended transition resolves.
Environment
- Octane 0.6.0, commit
1bebd3b2f3cadd672a772d7f27c444a14e7a0fa5(default branch fetched September 27, 2026). - macOS, Node 22.22.2, pnpm 11.15.1, Vitest 4.1.10, jsdom 30.0.1.
- Client mount using
octane({hmr:false})(production compiler path); ordinary Vitest runtime. No hydration or production-browser-bundle claim. - Matched public-API React/ReactDOM 19.2.7 control tested in the same jsdom harness.
Reproduction
At the revision above, run pnpm install --frozen-lockfile.
Save packages/octane/tests/_fixtures/evidence-a8f2-store.tsrx (the state-driven component is retained from the passing control):
import { use, useState, useSyncExternalStore, useTransition } from 'octane';
type Field = 'a' | 'b';
export interface Store {
get: () => Record<Field, number>;
subscribe: (fn: () => void) => () => void;
}
interface Props {
store: Store;
pending: Promise<void>;
tail: Promise<void>;
bind: (select: (field: Field) => void) => void;
observe: (field: Field) => void;
}
function Reader({ store, field, pending, tail, observe }: { store: Store; field: Field; pending: Promise<void>;
tail: Promise<void>; observe: Props['observe'] }) @{
const value = useSyncExternalStore(store.subscribe, () => { observe(field); return store.get()[field]; });
if (field === 'b') { use(pending); use(tail); }
<span id="value">{field + ':' + value}</span>
}
export function StoreTransition(props: Props) @{
const [field, setField] = useState<Field>('a');
const [isPending, start] = useTransition();
props.bind((next) => start(() => setField(next)));
<div>
<span id="pending">{isPending ? 'pending' : 'idle'}</span>
@try {
<Reader store={props.store} field={field} pending={props.pending} tail={props.tail} observe={props.observe} />
} @pending {
<span id="fallback">Loading</span>
}
</div>
}
export function RootSelection(props: Omit<Props, 'bind'> & { field: Field }) @{
@try {
<Reader store={props.store} field={props.field} pending={props.pending} tail={props.tail} observe={props.observe} />
} @pending {
<span id="fallback">Loading</span>
}
}Save packages/octane/tests/evidence-a8f2-store.test.ts:
import { expect, it } from 'vitest';
import { mount, act } from './_helpers';
import { startTransition } from 'octane';
import { RootSelection } from './_fixtures/evidence-a8f2-store.tsrx';
it('keeps a root-prop selection live while its transition suspends', async () => {
let current = { a: 0, b: 0 };
const listeners = new Set<() => void>();
const store = { get: () => current, subscribe: (fn: () => void) => { listeners.add(fn); return () => listeners.delete(fn); } };
let resolve!: () => void;
const pending = new Promise<void>(done => { resolve = done; });
const reads: string[] = [];
const props = { store, pending, tail: pending, observe: (field: 'a' | 'b') => reads.push(field) };
const root = mount(RootSelection, { ...props, field: 'a' });
try {
await act(() => {});
expect(root.find('#value').textContent).toBe('a:0');
await act(() => startTransition(() => root.root.render(RootSelection, { ...props, field: 'b' })));
expect(root.find('#value').textContent).toBe('a:0');
reads.length = 0;
await act(() => { current = { a: 1, b: 0 }; for (const listener of listeners) listener(); });
console.log('root-prop after notify', JSON.stringify({ html: root.html(), reads }));
expect.soft(root.find('#value').textContent).toBe('a:1');
await act(() => resolve());
expect(root.find('#value').textContent).toBe('b:0');
} finally { root.unmount(); }
});Save evidence-a8f2-store.config.mjs at the repository root:
import { defineConfig } from 'vitest/config';
import { octane } from './packages/octane/src/compiler/vite.js';
export default defineConfig({
plugins: [octane({ hmr: false })],
test: { cache: false, environment: 'jsdom', include: ['packages/octane/tests/evidence-a8f2-store.test.ts'], setupFiles: ['packages/octane/tests/_per-test-setup.ts'] },
});Run:
pnpm exec vitest run --config evidence-a8f2-store.config.mjs --reporter=verbose --silent=falseExpected / actual
- Render field
afrom{a:0,b:0}: displaysa:0. - Call
startTransition(() => root.render(RootSelection, {...props, field:'b'})). Fieldbsuspends;a:0remains visible. - Replace the store with
{a:1,b:0}and synchronously notify every subscriber. - Expected: the retained view updates to
a:1. Actual: it remainsa:0. - Resolve the promise: both Octane and React finish at
b:0.
The Octane failure reproduced in 3/3 full-suite runs, then again with the isolated test above. An equivalent React test using root.render(createElement(...)), Suspense, useSyncExternalStore, use, and startTransition passed 2/2 runs: it updated the retained view to a:1. State-driven Octane transitions also passed, including resuspension after an initial promise resolves.
Contract and likely cause
The store contract promises updates for notifying stores. The documented optimization exception concerns a mutation without notification during render-to-commit; this repro explicitly notifies after the suspended render. The per-swap limitation describes early content/structural commits outside the held boundary; this failure loses a store update inside its retained content.
The likely cause is inst.getSnapshot = getSnapshot during render. When notified, checkStoreChanged compares the last committed 0 against pending selector b=0, suppressing the update even though the visible selector a now returns 1. Diagnostic callbacks confirm the notification reads b; the failing assertion is rendered text, not callback counts. No production patch was used to establish causality.
Impact: roots driven by external navigation/embedding props can display stale subscribed data while the new selection is loading. No last-good revision was established. Historical #962 concerns a different TanStack Router selection cache; open #1066 addresses subscription-time initialization and retains this render-time getter assignment.
Activity
jonkwheeler commentedon Oct 27, 2026
Re-checked on current main (
232464b399, after the runtime redesign in #2103): this still reproduces. After the store notifies during the held root transition, the screen stays ata:0instead ofa:1.There are two causes, and fixing only the first makes things worse.
1. The selector write isn't rolled back. On an update render,
useSyncExternalStoreassignsinst.getSnapshot = getSnapshoton the shared store cell (packages/octane/src/runtime/engine.ts, around line 4628) without journaling it. When the root transition suspends into the@tryhold, the cell keeps the pending selector (b).checkStoreChanged(src/runtime/effects.ts:513) then compares the committed value againstb's value, sees no change, and drops the notification. Journaling the write fixes this step, and the notification check readsaagain:2. The re-render uses the held transition's props. A
root.rendertransition folds no hook work, so it holds per boundary. Content outside the suspended boundary commits early, including the root component's props. The re-render the notification forces then reaches the consumer throughrenderVisibleTrywithk: 'b'. It suspends onband shows the@pendingfallback. This is the limitation inpackages/octane/audit/SUSPENSE_DIVERGENCE.md§4 ("Remaining limitation — transitions not driven by hook state").With only the first change applied, the user sees a loading flash instead of a stale value, so it shouldn't land alone. The second cause needs root requests to drop the whole root transaction when they suspend into a boundary hold, as hook-driven transitions already do since #2029. #2043 is closed, but
packages/octane/audit/SUSPENSE_DIVERGENCE.md§4 still lists this limitation on main, so no open issue tracks this part of the fix yet.Regression test for whoever picks this up. It fails on main at the
a:1assertion:Fixture and test
packages/octane/tests/_fixtures/external-store-behavior.tsrx:packages/octane/tests/external-store-behavior.test.ts:Agent-authored investigation.
fix: hold root.render transitions that suspend into a held boundary (o…