Skip to content

feat: Reject Strong render-time ref reads - #1029

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:feat/strong-render-ref-read-1027
Sep 10, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:feat/strong-render-ref-read-1027

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add OCTANE_STRONG_RENDER_REF_READ as a source-located error for provable useRef.current reads during Strong render.
  • Keep compatibility modules, ref identities, and reads in events, effects, cleanup, and deferred callbacks legal.

Part of #1027.

Why

A ref can change without a render input changing. Strong render output that reads current can therefore become stale when compilation reuses a region.

Changes

  • Follow known ref aliases, optional and computed access, immediate hook results, object spread/rest, and destructured arguments to synchronous render helpers.
  • Preserve the existing ref-write diagnostic for writes; report nested reads and read-before-await compound assignments.
  • Add compiler and Volar regression coverage, client/server output parity tests, documentation, MCP guidance, and patch changesets for octane and @octanejs/mcp-server.

Validation

  • pnpm format:check (scoped pnpm format:files:check passed for all changed files)
  • pnpm typecheck
  • pnpm test (prechecks passed; full Vitest stopped after browser suites failed to launch Chromium in the local sandbox)
  • targeted tests: pnpm exec vitest run packages/octane/tests/compiler/strong-mode.test.ts --silent=passed-only (754 passed)
  • pnpm sync (no generated changes)
  • compiler throughput: paired baseline/candidate runs in both orders on the same host, Node, and dependencies; 1000-component Strong medians were 279.6→314.8 ms and 322.2→297.5 ms in reverse order (n=5 each), so timing is noisy with no repeatable regression. Output hashes and byte counts match for 10, 100, and 1000 components in both modes.

Risk / follow-ups

The static proof follows known refs and synchronous calls; opaque values remain outside this diagnostic. The remaining items in #1027 should land as separate PRs. Browser coverage needs CI because local Chromium exits before test bodies with MachPortRendezvousServer: Permission denied.

Provenance

  • An agent produced this diff (agent-authored)

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
Opt-in Strong mode gains a new compile-time error that can break apps reading refs during render; emitted code for valid modules is unchanged per tests.

Overview
Strong mode now rejects reading useRef object's current during render, not only assigning to it. Modules with "use strong" or compiler.strong: true get compile error OCTANE_STRONG_RENDER_REF_READ with source locations (compiler + Volar); compatibility modules are unchanged.

The Strong analyzer tracks ref identities through aliases, optional/computed .current, destructuring/spread, synchronous helpers (useMemo/useCallback/IIFEs), and compound assignments that read before await. Ref writes still use OCTANE_STRONG_RENDER_REF_WRITE; reads in events, effects, cleanup, and post-yield async paths stay allowed.

Docs (TSRX basics, React differences, build tools) and the MCP react-divergences skill document the rule. Patch changesets cover octane and @octanejs/mcp-server.

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

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 feat PR: new feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant