Skip to content

SSR signal values collide between rows with distinct object keys #1249

Closed

Description

@jonkwheeler

Observed failure

Two rows with distinct object keys initialize their own signal$(props.label), but renderToString emits the first row's value for both rows. Expected output values are ['first', 'second']; actual values are ['first', 'first']. This affects rendered row data before hydration, including a direct value$.get() read.

Environment

Tested current main at c25a18503ea30b27db09c3f60ff6b34afdfaf650: 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 compiler dev: false and dev: true use hmr: false, running inside Vitest's default test runtime. A separate NODE_ENV=production attempt failed during fixture-loader startup (No such built-in module: node:), before any test executed; it is not a production-runtime verification. This is source-checkout evidence; the published npm build and a real browser were not tested.

Reproduction

In an isolated checkout of the revision above, install the frozen dependencies:

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

The executed installation used a populated pnpm store; omit --offline on a machine that needs to download the locked packages. Save this isolated test 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({ hmr: false })],
  test: {
    environment: 'jsdom',
    include: ['packages/octane/tests/**/*.test.ts'],
    setupFiles: ['packages/octane/tests/_per-test-setup.ts'],
    env: { OCTANE_TEST_COMPILE_MODE: 'prod' },
    globals: false,
    testTimeout: 30000,
    maxWorkers: 2,
  },
});

Save the following as packages/octane/tests/evidence-signals-object-key-ssr.test.ts. It uses the repository's existing compiled-fixture loader and public APIs:

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

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

it.each([false, true])('isolates SSR signals for distinct object keys (dev=%s)', (dev) => {
  const server = loadCompiledFixtureSource(source, {
    id: '/evidence/object-key-signals.tsrx',
    mode: 'server',
    compileOptions: { dev, hmr: false },
    runtimeModules: { 'octane/signals': Signals },
  });
  const items = [
    { key: { id: 'a' }, label: 'first' },
    { key: { id: 'b' }, label: 'second' },
  ];
  const container = document.createElement('div');
  container.innerHTML = renderToString(server.App, { items }).html;
  expect([...container.querySelectorAll('output')].map(node => node.textContent))
    .toEqual(['first', 'second']);
});

Run:

pnpm exec vitest run --config evidence.vitest.config.mjs packages/octane/tests/evidence-signals-object-key-ssr.test.ts --reporter=verbose

Evidence and scope

Both cases fail on every run; the minimal reproduction was independently repeated in separate processes. A broader control matrix passes distinct primitive keys (including 1 versus '1'), string-key hydration, and object-key client-only mounting, edits and reordering. Object-key SSR fails before the hydration call. No last-good version or introducing commit has been established.

Instance-local signal ownership is documented in docs/signals.md. The server explicitly preserves stable object-key identity for list arms (source), and existing object-key SSR coverage covers ordinary text rows without reading signals.

Cause and related work

signalIdentityKey maps both plain objects to o:[object Object]. List identity construction includes that value, so serverSignalOwner looks up and reuses the same signal instance for both rows.

Related #1147 fixes eager object-key coercion when no signal is read. This reproduction reads an actual component-local signal and demonstrates a value collision; it does not claim the earlier fix regressed.

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