Skip to content

SSR repeats the first row signal value for declarations inside keyed @for #1256

Closed

Description

@jonkwheeler

Observed failure

A signal$ declared directly inside a keyed @for shares the first row's initial value during SSR. For two rows with distinct string keys and labels first / second, client mounting renders first, second, but SSR renders first, first.

Environment

Tested main at 1871491dea5602ed6ac51fcc63ac9bbf7b133915: Octane 0.4.2, @tsrx/core 0.2.0, @tsrx/oxc 0.13.0, Node 22.22.2, pnpm 11.15.1, Vitest 4.1.10, jsdom 30.0.1, macOS 26.6.2 arm64. Both development and production compiler modes (dev: true/false, hmr: false) were exercised under Vitest's default test runtime. Published packages and a real browser were not tested.

Reproduction

In a checkout of the revision above, install the locked dependencies:

pnpm install --frozen-lockfile --ignore-scripts --filter octane --filter . --filter @octanejs/stylex

The investigation used this command with --offline and an already populated pnpm store. Save this scoped configuration as evidence.vitest.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()],
 test: {
  environment: 'jsdom',
  include: ['packages/octane/tests/**/*.test.ts'],
  setupFiles: ['packages/octane/tests/_per-test-setup.ts'],
  globals: false,
  fileParallelism: false,
  testTimeout: 30000,
 },
});

Save this test as packages/octane/tests/evidence-inline-signal-minimal.test.ts. It uses the existing compiled-fixture loader and checks the same authored component through public client/server APIs:

import { expect, it } from 'vitest';
import { createRoot } from 'octane';
import { renderToString } from 'octane/server';
import * as Signals from 'octane/signals';
import { loadCompiledFixtureSource } from './_server-fixture.js';

const source = `import { signal$ } from 'octane/signals';
export function App(props) @{
  <main>@for (const item of props.items; key item.id) {
    const value$ = signal$(item.label);
    <output>{String(value$.get())}</output>
  }</main>
}`;

it.each([false, true])('isolates signals declared inside keyed rows (dev=%s)', (dev) => {
  const options = {
    id: '/src/inline-row-signals.tsrx',
    compileOptions: { dev, hmr: false },
    runtimeModules: { 'octane/signals': Signals },
  };
  const client = loadCompiledFixtureSource(source, { ...options, mode: 'client' });
  const server = loadCompiledFixtureSource(source, { ...options, mode: 'server' });
  const props = { items: [{ id: 'a', label: 'first' }, { id: 'b', label: 'second' }] };
  const host = document.createElement('div');
  const values = () => [...host.querySelectorAll('output')].map(node => node.textContent);
  const root = createRoot(host);
  try {
    root.render(client.App, props);
    expect(values()).toEqual(['first', 'second']);
  } finally { root.unmount(); }
  host.innerHTML = renderToString(server.App, props).html;
  expect(values()).toEqual(['first', 'second']);
});

Run:

pnpm exec vitest run --config evidence.vitest.config.mjs packages/octane/tests/evidence-inline-signal-minimal.test.ts --reporter=verbose

Both client assertions pass. Both final SSR assertions fail:

Expected: [ 'first', 'second' ]
Received: [ 'first', 'first' ]

Evidence and impact

The minimal test was repeated in two fresh processes: both compiler modes failed at the SSR assertion on each run. A separate matrix repeated twice also reproduces this in renderToString, renderToStaticMarkup, prerender (from octane/static), readable streams, and pipeable streams: 10 failing SSR cases and 2 passing client controls per run.

This emits incorrect row content in server HTML before hydration. Moving the declaration into a child Row component preserves independent values; eight child-component cases with mixed/opaque keys and nested lists also pass SSR, hydration, editing, and reordering. No last-good revision, introducing commit, or hydration consequence for the failing inline case is claimed.

Contract and likely cause

Signal ownership is instance-local. The compiler accepts this keyed declaration, and client rendering gives each row its own value.

Likely cause: ssrForItem changes list/async identity but invokes the inline body under the enclosing component's signal owner. serverSignalOwner derives its identity from SIGNAL_COMPONENT_INSTANCE_KEY. The repeated declaration site therefore appears to resolve against one owner rather than separate row owners.

Related #1249, fixed by #1252, concerned opaque keys on child components. This reproduction runs after that fix, uses ordinary string keys, and declares the signal directly in the loop. It does not establish a regression caused by that fix.

Provenance

  • Agent-authored report and reproduction.

Activity

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