Skip to content

Keyed child disappears after a pending update is superseded #1698

Description

@domgan-oai

A keyed child inside an @try boundary can disappear when a pending update is followed by an update that no longer suspends. The outer component commits all three inputs, and the pending fallback for B is visible before returning to A; afterward the outer A is rendered but the child is missing.

Reproduction

Observed using public Octane 0.9.0 source at 76b5b026713cbdc153b0d6786c1b1ecc952e8893, Node 26.2.0, Vitest 4.1.11 and jsdom. Both Strong development and production compilation fail. This tests the source; the published npm tarball was not independently compared.

In an Octane checkout at that commit, install its dependencies, save the following files, and run from the checkout root:

pnpm exec vitest run --config keyed-pending-repro.config.mjs

Each case commits A, then B, then A. When the B update suspends, its pending fallback is explicitly checked before returning to A. Expected: the final child shows A. Actual: the outer label shows A but the child is absent. The keyed/suspending case fails in both compilation modes; the other six controls (unkeyed, no suspension, or both) pass. The assertion does not require the original child instance or useId to be retained.

packages/octane/tests/keyed-pending-repro.test.ts
import { expect, it } from 'vitest';
import { createRoot, flushSync } from 'octane';
import { loadCompiledFixtureSource } from './_server-fixture.js';

function source(keyed: boolean) {
  return `import { use, useLayoutEffect } from 'octane';
function Child(props) @{ <span>{props.selection as string}</span> }
function Hold(props) @{ use(props.wait); <i>ready</i> }
export function App(props) @{
  useLayoutEffect(() => { props.onCommit(props.selection); });
  <main>
    <b>{props.selection as string}</b>
    @try {
      <>
        <Child ${keyed ? 'key={props.selection}' : ''} selection={props.selection} />
        @if (props.wait) { <Hold wait={props.wait} /> }
      </>
    } @pending { <p>pending</p> }
  </main>
}`;
}

for (const dev of [true, false]) {
  for (const keyed of [true, false]) {
    for (const suspend of [true, false]) {
      it(`restores A (dev=${dev}, keyed=${keyed}, suspend=${suspend})`, async () => {
        const { App } = loadCompiledFixtureSource(source(keyed), {
          id: '/keyed-pending-repro.tsrx', mode: 'client',
          compileOptions: { strong: true, dev, hmr: false },
        });
        const host = document.createElement('div');
        const root = createRoot(host);
        const commits: string[] = [];
        const props = { selection: 'A', wait: undefined, onCommit: (s: string) => { commits.push(s); } };
        const drain = async () => {
          for (let i = 0; i < 12; i++) { await Promise.resolve(); flushSync(() => {}); }
        };
        try {
          root.render(App, props);
          flushSync(() => {});
          await drain();
          expect(host.querySelector('span')?.textContent).toBe('A');
          root.render(App, { ...props, selection: 'B', wait: suspend ? new Promise(() => {}) : undefined });
          flushSync(() => {});
          await drain();
          expect(host.querySelector('b')?.textContent).toBe('B');
          if (suspend) expect(host.querySelector('p')?.textContent).toBe('pending');
          else expect(host.querySelector('span')?.textContent).toBe('B');
          root.render(App, props);
          flushSync(() => {});
          await drain();
          expect(commits).toEqual(['A', 'B', 'A']);
          expect(host.querySelector('b')?.textContent).toBe('A');
          expect(host.querySelector('span')?.textContent).toBe('A');
        } finally { root.unmount(); }
      });
    }
  }
}
keyed-pending-repro.config.mjs
import path from 'node:path';
const src = path.resolve('packages/octane/src');
export default {
  resolve: { alias: [
    { find: /^octane$/, replacement: `${src}/index.ts` },
    { find: /^octane\/internal\/client$/, replacement: `${src}/internal/client.ts` },
    { find: /^octane\/internal\/server$/, replacement: `${src}/internal/server.ts` },
    { find: /^octane\/compiler$/, replacement: `${src}/compiler/index.js` },
    { find: /^octane\/signals$/, replacement: `${src}/signals/index.ts` },
  ] },
  test: { include: ['packages/octane/tests/keyed-pending-repro.test.ts'], environment: 'jsdom' },
};

Activity

  1. added a commit that references this issue on Oct 4, 2026
    4c7ae9b
  2. added a commit that references this issue on Oct 7, 2026
    773a069
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions