Skip to content

fix(compiler): keep .tsrx signal declaration modules renderer-free - #1289

Merged
domgan-oai merged 1 commit into
mainfrom
fix/tsrx-signal-module-renderer-leak
Sep 23, 2026
Merged

domgan-oai merged 1 commit into
mainfrom
fix/tsrx-signal-module-renderer-leak

Conversation

@trueadm

@trueadm trueadm commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A client .tsrx module that only declares signals (signal$/derived$/query$, no components or renderer imports) loaded the renderer. It emitted enableNativeReadCollection(1) and enableSignalBindings(1) from octane/internal/client.
  • Any renderer-free consumer of those signals, such as adoptBindings, therefore bundled the renderer.
  • Such a module now activates only the document signal owner, through __enableSignalDocument(1) from octane/signals. That is exactly what the plain .ts compile path already emits for the same source.

Why

In compile.js, the signal declarations add enableSignalBindings to ctx.runtimeNeeded. nativeReadActivationNodes then treated that non-empty set as renderer work and installed the native-read driver as well. Declaring signals ended up enabling the renderer.

docs/signals.md makes the reading module responsible for activation: "Each module that consumes native reads needs a runtime import from octane/signals…". slot-hooks.js already follows that rule for .ts modules.

Measured with the same signal-driven view adopted through adoptBindings (esbuild, production, gzip-9), signals declared in a .tsrx module:

Before After
Bundle 154,502 raw / 48,585 gzip / 43,245 br 81,897 raw / 24,781 gzip / 22,301 br
runtime.ts in bundle 63,205 raw none

The same declarations in a plain .ts module: 24,163 gzip. This came out of measuring renderer-free islands for #1284.

Changes

  • compiler/compile.js: a doesRendererWork(ctx) check (generated runtime helpers, or a renderer import) is now shared by the native-read activation and the signal-binding activation. It mirrors the .ts policy in slot-hooks.js. When a module's eager signal declarations are its only work, it emits __enableSignalDocument(1).
  • Unchanged:
    • modules with components or renderer imports;
    • reader modules with a bare import 'octane/signals';
    • all server output, which already uses enableServerSignalBindings.
  • docs/signals.md: states that importing handles from a declaring module does not enable native reads.
  • benchmarks/conversation-streaming/fixture: Body.tsrx and History.tsrx read body$.get()/history$.get() during render without the documented import. They only updated because State.tsrx switched on native-read collection for the whole app. Each is an independent island whose graph is just itself plus State.tsrx, so both now declare import 'octane/signals'.

Behavior change

A component that reads signals during render without importing octane/signals no longer gets native-read collection from the .tsrx module that declares them. This already applied when the declarations lived in a .ts module, and the docs have always required the import.

In the repo, only the two benchmark fixture components above relied on it. examples/signal-chat/src/Composer.tsrx and the benchmark Composer.tsrx read signal values only in event handlers, which never subscribe. Every other module that reads the affected State.tsrx files imports octane/signals.

Validation

  • New CI test in benchmarks/scoped-signals/bundle-boundaries.test.mjs (runs in ci:workflow:test), with two parts:
    • Renderer-free declarations: a declarations-only .tsrx module plus the owner APIs must not resolve runtime.ts or internal/client.ts, and its derived value must update ([2, 8]). This part fails on main ("Signal declarations reached the renderer").
    • Control: a reader with the documented bare import reads through a parameter default. That read happens before the component body, so only module-level activation collects it. The reader must re-render (1 → 5) in happy-dom. It fails (stays 1) if native-read activation is removed from renderer modules too.
  • packages/octane/tests/compiler: 2,640 passed.
  • All signal projects (node, dev, prod, strong): 814 passed.
  • Hydration directory, streamed cancellation, universal transport, behavior roots, binding handoff, scalar and signal DOM bindings, in dev and prod: 2,654 passed.
  • packages/vite-plugin-octane/tests/production.test.ts, which builds the fixture app containing a declarations-only State.tsrx: 19 passed.
  • bundle-boundaries, split-context, split-hydrate and deferred boundary tests, plus the conversation-streaming behavior-only server test: 46 passed.
  • pnpm format:files:check, pnpm changeset:check, pnpm sync. pnpm typecheck:files fails only on the fixture's unchanged backend.ts (@octanejs/app-core does not resolve there), and it fails identically on main.
  • Not run locally: the conversation-streaming real-browser runner (run-browser.mjs) and repo-wide pnpm test/pnpm typecheck. The repo-wide ones are left to CI.

Risk / follow-ups

  • The risk is external code that broke the documented import rule and relied on the side effect. It fails quietly: those components stop re-rendering on signal changes. A development diagnostic for a native read during render in a module without the import would make this discoverable. Suggested follow-up.
  • Follow-ups in Reduce runtime reachability for scoped signals and fixed-node bindings #1284: renderer-free island activation, and a route mode that skips the shell.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Compiler emission changes which modules load the renderer; apps that read signals during render without import 'octane/signals' and relied on the declaring .tsrx module's side effect may stop re-rendering silently.

Overview
.tsrx modules that only declare signals (signal$ / derived$ / query$, with no components or renderer imports) no longer pull in the Octane renderer on load. They now emit __enableSignalDocument(1) from octane/signals, matching plain .ts modules, instead of enableSignalBindings / enableNativeReadCollection from octane/internal/client. Renderer-free consumers such as adoptBindings can import those state modules without bundling runtime.ts (~24 KB gzip in a cited measurement).

The compiler adds shared doesRendererWork(ctx) (generated runtime helpers or non-type renderer imports) and uses it for both signal-binding activation and native-read activation. Modules that actually render still activate native reads via their own documented import 'octane/signals'.

docs/signals.md states that importing handles from a declaring module does not enable native reads. Body.tsrx and History.tsrx in the conversation-streaming fixture add that import because they read signals during render. A new bundle-boundaries test locks in renderer-free declaration bundles and a control that reader modules still re-render when signals change.

Reviewed by Cursor Bugbot for commit fa9803a. Bugbot is set up for automated code reviews on this repo. Configure here.

A client .tsrx module that only declares signals emitted
enableNativeReadCollection(1) and enableSignalBindings(1) from
octane/internal/client. The declarations themselves added enableSignalBindings
to the module's runtime helpers, and that non-empty set then counted as
renderer work. Any renderer-free consumer, such as adoptBindings, bundled the
renderer: 48,585 instead of 24,781 bytes gzip in a measured example.

Such a module now activates only the document signal owner, through
__enableSignalDocument from octane/signals, exactly like the plain .ts path.
Modules that render signal reads keep activating native reads through their
documented octane/signals import. Two conversation-streaming fixture
components that read signals during render without that import now declare it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review September 23, 2026 20:59
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 23, 2026
@domgan-oai
domgan-oai merged commit a95c2dc into main Sep 23, 2026
23 of 41 checks passed
@domgan-oai
domgan-oai deleted the fix/tsrx-signal-module-renderer-leak branch September 23, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants