Skip to content

A held ViewTransition accepts a stale pending derived after its dependency changes #1767

Closed

Description

@domgan-oai

A component-local derived value can remain pending after a dependency becomes ready during a held View Transition. The newly staged content is committed, but an event handler still observes the old pending snapshot.

Environment

Reproduced on main at fb404c24dfb81d2174303a5b1852d715b8479c79, Node 26.2.0, Vitest 4.1.11 and jsdom. This is a client-rendered test, using the repository's View Transition test mocks.

Reproduction

Save packages/octane/tests/_fixtures/waiter-staged-public.tsrx:

import { ViewTransition } from 'octane';
import { derived$, type SignalHandle } from 'octane/signals';

interface Props {
  ready$: SignalHandle<boolean>;
  waiting: Promise<void>;
  version: number;
  capture: (s: string) => void;
}

function Child(props: Props) @{
  const value$ = derived$(({ read }) => {
    void read;
    if (!props.ready$.get()) throw props.waiting;
    return 'ready:' + String(props.version);
  });
  const snapshot = value$.snapshot();
  <section>
    <button onClick={() => {
      const current = value$.snapshot();
      props.capture(current.status === 'ready' ? current.value : current.status);
    }}>{props.version === 0 ? 'Short' : 'Much longer content here'}</button>
    <output>{snapshot.status === 'ready' ? snapshot.value : snapshot.status}</output>
  </section>
}

export function StagedWaiter(props: Props) @{
  <ViewTransition update="auto">
    <div><Child {...props} /></div>
  </ViewTransition>
}

Save packages/octane/tests/waiter-staged-public.test.ts:

import { expect, it } from 'vitest';
import { createRoot, flushSync, startTransition } from '../src/index.js';
import { createScope } from 'octane/signals';
import { act } from './_helpers.js';
import { installViewTransitionMocks } from './conformance/_helpers/view-transition-mocks.js';
import { StagedWaiter } from './_fixtures/waiter-staged-public.tsrx';

for (const updateBeforeAcceptance of [true, false]) {
  it(`reflects a dependency update ${updateBeforeAcceptance ? 'before' : 'after'} staged acceptance`, async () => {
    const mocks = installViewTransitionMocks();
    const handles: Array<{ update: () => void | Promise<void>; finish: () => void }> = [];
    (document as any).startViewTransition = (input: { update: () => void | Promise<void> } | (() => void)) => {
      let finish!: () => void;
      const pending = new Promise<void>((resolve) => { finish = resolve; });
      handles.push({ update: typeof input === 'function' ? input : input.update, finish });
      return { ready: pending, finished: pending, skipTransition() {} };
    };
    const scope = createScope({ scopeKey: 'staged' });
    const ready$ = scope.signal$('ready', false);
    const waiting = new Promise<void>(() => {});
    const seen: string[] = [];
    const container = document.createElement('div');
    document.body.append(container);
    const root = createRoot(container);
    const props = { ready$, waiting, capture: (s: string) => seen.push(s) };
    try {
      await act(() => root.render(StagedWaiter, { ...props, version: 0 }));
      expect(container.querySelector('output')?.textContent).toBe('pending');
      await act(() => startTransition(() => root.render(StagedWaiter, { ...props, version: 1 })));
      expect(handles).toHaveLength(1);
      expect(container.querySelector('button')?.textContent).toBe('Short');
      if (updateBeforeAcceptance) await act(() => ready$.set(true));
      for (const handle of [...handles]) { await handle.update(); handle.finish(); }
      await act(() => {});
      expect(container.querySelector('button')?.textContent).toBe('Much longer content here');
      if (!updateBeforeAcceptance) await act(() => ready$.set(true));
      expect(ready$.get()).toBe(true);
      flushSync(() => (container.querySelector('button') as HTMLButtonElement).click());
      expect(seen.at(-1)).toBe('ready:1');
      expect(container.querySelector('output')?.textContent).toBe('ready:1');
    } finally {
      for (const handle of handles) handle.finish();
      flushSync(() => root.unmount());
      scope.dispose();
      container.remove();
      mocks.restore();
    }
  });
}

Save vitest.waiter-staged-public.config.mjs at the repository root:

import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { defineConfig } from "vitest/config";
import { octane } from "./packages/octane/src/compiler/vite.js";
import { scopedSignalsProjects } from "./scripts/scoped-signals-projects.mjs";
const packageRoot = resolve("./packages/octane");
const pkg = JSON.parse(readFileSync(resolve(packageRoot, "package.json"), "utf8"));
const alias = Object.entries(pkg.exports).map(([name, target]) => ({
  find: name === "." ? "octane" : "octane" + name.slice(1),
  replacement: resolve(packageRoot, typeof target === "string" ? target : target.default),
})).sort((a, b) => b.find.length - a.find.length);
process.env.OCTANE_COMPILE_FROZEN_AST ??= "1";
process.env.OCTANE_COMPILE_ASSERT_LOC ??= "1";
export default defineConfig({ test: { projects: scopedSignalsProjects(octane)
  .filter((p) => ["octane-signals", "octane-signals-prod", "octane-signals-strong"].includes(p.test?.name))
  .map((p) => ({ ...p, root: resolve(packageRoot, "tests"), resolve: { alias },
    test: { ...p.test, include: ["waiter-staged-public.test.ts"], exclude: [], setupFiles: [resolve(packageRoot, "tests/_per-test-setup.ts")], testTimeout: 6000 } })) } });

Run:

pnpm exec vitest run --config vitest.waiter-staged-public.config.mjs --maxWorkers=1 --no-file-parallelism

The first case holds the browser's View Transition update callback, changes the dependency, and then releases the callback. The second case is a control which changes the same dependency after acceptance.

Expected: Both cases commit the changed content, and subsequent reads and rendering show ready:1.

Actual: In the before-acceptance case, the new button text is committed and the dependency is true, but the button reads pending. The after-acceptance control passes. This occurs in each of the development, production, and Strong compiler test configurations: three failing and three passing cases.

Investigation

A private declaration view is pending when rendered and its dependency changes before promotion. At the graph-operation level, promoting the invalidated view clears its dirty state; a later read can therefore return the stale pending state. A diagnostic change retaining this invalidation during promotion makes both cases pass in all three configurations. That experiment is not a proposed fix and does not establish safety for the other promotion lifecycles.

Activity

  1. domgan-oai commented on Oct 5, 2026

    @domgan-oai
    ContributorAuthor

    A staged render can commit a stale ready derived value when its new dependency changes before the transition update is accepted.

    Verified on Octane main at fb404c24dfb81d2174303a5b1852d715b8479c79, using the existing transition test helper and Vitest setup. The test replaces the derived computation's source while holding a view transition, changes the new source from false to true, and accepts the transition.

    Expected: the rendered text and the retained derived signal both read new. Actual: both remain old. As a control, moving next$.set(true) to after handles[0].update() and transition completion updates both to new.

    To reproduce, add these files to a checkout at the above commit and run:

    node ./node_modules/vitest/vitest.mjs run --config vitest.ready-view-held-1775.config.mjs --project octane-signals --reporter=dot

    packages/octane/tests/_fixtures/ready-view-held-1775.tsrx

    import { ViewTransition } from 'octane';
    import { captureSignalOwner, currentSignalOwner, derived$, type SignalHandle } from 'octane/signals';
    
    export interface ReadyProps {
      source$: SignalHandle<boolean>;
      version: number;
      capture(read: () => string): void;
    }
    function Child(props: ReadyProps) @{
      const value$ = derived$(({read}) => {
        void read;
        return props.source$.get() ? 'new' : 'old';
      });
      const value = value$.get();
      const run = captureSignalOwner(currentSignalOwner()!);
      <button onClick={() => props.capture(() => run(() => value$.get()))}>
        {props.version === 0 ? 'Short' : 'Much longer content here'}
        <span>{value}</span>
      </button>
    }
    export function ReadyStaged(props: ReadyProps) @{
      <ViewTransition update="auto"><div><Child {...props} /></div></ViewTransition>
    }

    packages/octane/tests/ready-view-held-1775.test.ts

    import { expect, it } from 'vitest';
    import { act, createRoot, flushSync, startTransition } from 'octane';
    import { createScope } from 'octane/signals';
    import { installViewTransitionMocks } from './conformance/_helpers/view-transition-mocks.js';
    import { ReadyStaged } from './_fixtures/ready-view-held-1775.tsrx';
    
    it('refreshes a ready derived invalidated before the staged view is accepted', async () => {
      const mocks = installViewTransitionMocks();
      const handles: Array<{update: () => void | Promise<void>, finish: () => void}> = [];
      (document as any).startViewTransition = (input: {update: () => void | Promise<void>} | (() => void)) => {
        let finish!: () => void;
        const completed = new Promise<void>((resolve) => {finish = resolve;});
        handles.push({update: typeof input === 'function' ? input : input.update, finish});
        return {ready: completed, finished: completed, skipTransition() {}};
      };
      const scope = createScope({scopeKey: 'ready-view'});
      const first$ = scope.signal$('first', false);
      const next$ = scope.signal$('next', false);
      let read: (() => string) | undefined;
      const capture = (callback: () => string) => {read = callback;};
      const container = document.createElement('div');
      document.body.append(container);
      const root = createRoot(container);
      try {
        await act(() => root.render(ReadyStaged, {source$: first$, version: 0, capture}));
        flushSync(() => (container.querySelector('button') as HTMLButtonElement).click());
        expect(read!()).toBe('old');
        await act(() => startTransition(() => root.render(ReadyStaged, {source$: next$, version: 1, capture})));
        expect(handles).toHaveLength(1);
        next$.set(true);
        await handles[0]!.update();
        handles[0]!.finish();
        await act(() => {});
        expect(container.querySelector('span')!.textContent).toBe('new');
        expect(read!()).toBe('new');
      } finally {
        for (const handle of handles) handle.finish();
        flushSync(() => root.unmount());
        scope.dispose();
        container.remove();
        mocks.restore();
      }
    });

    vitest.ready-view-held-1775.config.mjs

    import { readFileSync } from "node:fs";
    import { resolve } from "node:path";
    import { defineConfig } from "vitest/config";
    import { octane } from "./packages/octane/src/compiler/vite.js";
    import { scopedSignalsProjects } from "./scripts/scoped-signals-projects.mjs";
    const packageRoot = resolve("./packages/octane");
    const pkg = JSON.parse(readFileSync(resolve(packageRoot, "package.json"), "utf8"));
    const alias = Object.entries(pkg.exports).map(([name, target]) => ({
      find: name === "." ? "octane" : "octane" + name.slice(1),
      replacement: resolve(packageRoot, typeof target === "string" ? target : target.default),
    })).sort((a, b) => b.find.length - a.find.length);
    process.env.OCTANE_COMPILE_FROZEN_AST ??= "1";
    process.env.OCTANE_COMPILE_ASSERT_LOC ??= "1";
    export default defineConfig({ test: { projects: scopedSignalsProjects(octane)
      .filter((p) => ["octane-signals", "octane-signals-prod", "octane-signals-strong"].includes(p.test?.name))
      .map((p) => ({ ...p, root: resolve("."), resolve: { alias },
        test: { ...p.test, include: ["packages/octane/tests/ready-view-held-1775.test.ts"], exclude: [], setupFiles: [resolve(packageRoot, "tests/_per-test-setup.ts")], testTimeout: 6000 } })) } });
  2. added a commit that references this issue on Oct 6, 2026
    ab9a043
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