Skip to content

fix: stabilize Strong literal props and permit manual useMemo and useCallback - #2047

Merged
trueadm merged 5 commits into
octanejs:mainfrom
openai-oss-forks:fix/strong-literal-memo
Oct 13, 2026
Merged

trueadm merged 5 commits into
octanejs:mainfrom
openai-oss-forks:fix/strong-literal-memo

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Strong mode now keeps eligible ref arrays and literal component props stable on unrelated renders, and allows authors to use useMemo and useCallback with their own dependency lists.

Closes #2045
Closes #2046

Why

<div ref={[frameRef, props.imageFrameRef]}> previously detached and reattached unchanged refs. An inline context value, including const context = { inline: node.type === "text" }, could restart subscriptions on unrelated changes. Strong mode also rejected manual useMemo and useCallback, leaving no direct way to control when a value or callback changes.

Changes

  • Reuse the existing calculation cache and member-path dependency inference for Strong literal props/ref arrays in dev and production. Named literals must flow directly to eligible props or refs; other setup/handler uses preserve fresh mutable locals.
  • Allow authored useMemo and useCallback, including aliases, with explicit arrays, inferred omitted/undefined deps, and null. Preserve Strong effect, purity, and native-read policies; retire the obsolete manual-memo diagnostic and fix.
  • Preserve authored callback identity for aliased useCallback: production must not hoist a capture-free function whose identity depends on authored deps.
  • Update compiler/editor/CLI diagnostics, migration fixes, generated catalogs and public docs; add an Octane patch changeset.

Validation

  • Final-head CI at cafd81d: all CI jobs and PR benchmarks passed. Includes all 4 Node test and React parity shards, Chromium, package/eval integrations, lint, typechecks, bundle gates, examples and provenance.

  • Final receiver regression: event mutation reproduces 4/4 failures before the fix; full dev/prod hook-cache suites pass 124/124 after it. Independent complexity review completed.

  • pnpm sync (existing exact-lock dependencies; PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN=false avoids automatic reinstallation)

  • Targeted compiler/runtime tests: 102 passed across hook cache, ownership and auto-calculation; separate mutation controls 8 passed.

  • Final useMemo/useCallback policy, runtime, native, diagnostic and migration suites: 1,130 tests passed (7 files, octane + octane-prod); CLI analyze 26 passed.

  • Before fix, all 4 useCallback cases failed the Strong ban; 2 capture-free aliased callback cases then failed specifically in production. Both regressions pass after the fix.

  • Before-fix regressions: 8/8 .tsrx/.tsx dev/prod ref/context tests failed for observable lifecycle churn; restoring the original ban makes all 6 manual memo tests fail.

  • Existing benchmarks/template-call-memo/run.mjs baseline and candidate: controls pass, all operation counts unchanged, Strong compiled 4770 B and bundled gzip 62944 B before/after. Compatibility unchanged (3817 B / 62471 B).

  • Full changed-file formatting check with the repository's Prettier configuration.

  • Broad core octane/octane-prod local run: 45,451 tests passed; missing web3 dependencies and load/timeouts prevented a clean full run. Rerunning affected compiler/hydration/SSR suites at 2 workers passed 1,047/1,048; the sole remaining failure is an absolute 6 s timing bound on a 10,000-row, non-Strong plain JS parse (23 s on this machine).

  • Repository-wide pnpm test, pnpm typecheck, pnpm format:check (targeted alternatives used).

Risk / follow-ups

Automatic literal caching conservatively excludes receiver-capable regular functions, methods and accessors, even a function that does not actually use its receiver. Array entries can also be invoked as methods (array[0]()); without deeper call-site proof they have the same escape. That can forgo automatic stability in some callback/ref cases. Explicit useMemo remains available when the author deliberately wants to retain such a literal. Arrow properties and existing ref identifiers remain eligible.

Ordinary JSX functions that have no proven hook/render ownership, deferred boundaries, server-only computations, and native/universal lowering keep their existing rules. Mutable local values that escape setup or are captured by callbacks remain live. The benchmark measures generated size and deterministic work, not browser latency or every consumer's whole bundle.

Provenance

  • An agent produced this diff (agent-authored)

Codex task · host com-79386


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


Note

Medium Risk
Changes Strong-mode compiler memoization and hook policy, affecting ref/context identity and when effects re-run; broad doc/tooling surface but behavior is covered by new tests.

Overview
Strong mode no longer bans useMemo and useCallback. Authors can use explicit dependency arrays, omit/undefined for inference, or null for every-render behavior; effects and imperative handles still enforce inferred deps (OCTANE_STRONG_EXPLICIT_DEPENDENCIES / OCTANE_STRONG_UNTRACKED_EFFECT scoped to those hooks). The OCTANE_STRONG_MANUAL_MEMO diagnostic, migration recipe, and octane analyze --fix rewrites that stripped memo hooks are removed.

The compiler adds strongLiteralMemo so eligible object/array literals and ref arrays passed straight to props or refs keep stable identity when their tracked inputs are unchanged—including locals assigned before JSX. Literals that escape setup, are captured by callbacks, or are mutated stay on ordinary JavaScript lifetimes. Literal caching uses member-path dependencies instead of whole-binding identity.

Docs, CLI/MCP catalogs, and tests are updated to match; new runtime/compiler tests cover ref churn, context subscriptions, mutable props, and manual memo/callback deps (including aliased useCallback in production).

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

@domgan-oai
domgan-oai marked this pull request as ready for review October 13, 2026 19:18
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 13, 2026
@domgan-oai domgan-oai changed the title fix: stabilize Strong literal props and allow manual useMemo dependencies fix: stabilize Strong literal props and permit manual useMemo and useCallback Oct 13, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/octane/src/compiler/compile.js Resolved
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares e75d7a82b, the merge commit's first parent with 0b8a40bff on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 4.625 4.758 ±0.0% −6.1% … +4.5% ⚪ within noise
octane-tsrx replace 13.942 13.458 +3.0% −2.9% … +7.6% ⚪ within noise
octane-tsrx add 3.842 3.892 −5.7% −14.3% … +6.8% ⚪ within noise
octane-tsrx update 0.175 0.186 +3.8% −2.5% … +12.7% ⚪ within noise
octane-tsrx select 0.009 0.009 −4.5% −10.2% … +0.8% ⚪ within noise
octane-tsrx swap 0.027 0.028 −0.5% −8.5% … +15.1% ⚪ within noise
octane-tsrx remove 0.026 0.023 −2.5% −9.6% … +7.3% ⚪ within noise
octane-tsrx runlots 34.300 37.183 −0.1% −8.0% … +7.7% ⚪ within noise
octane-tsrx select_lots 0.008 0.008 −8.0% −15.0% … −0.6% ⚪ within noise
octane-tsrx clear 73.642 74.392 +0.1% −8.7% … +9.2% ⚪ within noise
octane-jsx run 4.275 4.050 −3.6% −10.2% … +3.8% ⚪ within noise
octane-jsx replace 10.725 9.792 −3.4% −6.3% … +3.4% ⚪ within noise
octane-jsx add 3.967 4.050 +2.6% −2.5% … +7.1% ⚪ within noise
octane-jsx update 0.314 0.307 −0.4% −6.1% … +2.5% ⚪ within noise
octane-jsx select 0.148 0.143 +1.9% −2.5% … +4.1% ⚪ within noise
octane-jsx swap 0.178 0.179 +0.6% −0.6% … +2.2% ⚪ within noise
octane-jsx remove 0.185 0.182 +2.3% +0.3% … +4.3% ⚪ within noise
octane-jsx runlots 33.758 32.225 −2.0% −5.2% … +2.8% ⚪ within noise
octane-jsx select_lots 2.207 2.014 −3.5% −11.4% … +5.4% ⚪ within noise
octane-jsx clear 73.033 71.850 +2.3% −8.0% … +10.6% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 93 measured values.

Public-import reachability bundles (bytes)

No changes across 120 measured values.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit cafd81d. Configure here.

// the literal binding. Keep receiver-owning methods/accessors fresh.
// Arrow properties cannot acquire the literal as their `this`.
if (includesLiteral && n.type !== 'ArrowFunctionExpression') blocked = true;
return; // does not run during render

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-method functions break literal stability

Medium Severity

When Strong literal caching walks an object or array, any non-arrow FunctionExpression sets blocked, not only methods and accessors. Callbacks, IIFEs, and function ref entries do not receive that literal as this, but they still skip the cache. Unrelated renders then allocate a new ref array or context value and restart attachments or subscriptions.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cafd81d. Configure here.

@trueadm
trueadm merged commit 3d5994c into octanejs:main Oct 13, 2026
32 checks passed
trueadm added a commit that referenced this pull request Oct 15, 2026
Brings in #2047-#2051 (Strong literal stabilisation), #2054 (checked
compiled boundaries and a compiled router entry), #2055/#2057 (Strong
rejects descriptor APIs and .tsx/.jsx), #2056/#2060/#2061 (CLI Strong
reports), #2062 (Strong in the website and devtools), #2065 (no
browser-translation DOM accommodations) and Version Packages.

Conflicts, resolved so main's behaviour lands on the redesign's commit model:
- runtime.ts, #2065: setText keeps main's legacy host-only convention and the
  redesign's hydration writeText. The translator recovery is gone from
  renderText/commitText, setRenderText/commitSetText, commitHole,
  childTextHoleUpdate, recordHole and bindSignalChild; removeOnlyChildText
  still removes a committed Text at commit. resetOnlyChildHost and
  PENDING_HOST_TEXTS (which served only the host-only text writes) are deleted.
- compile.js, #2065: text updates call setRenderText(_txt, v), commit
  functions setText(_txt, v), and commitHole takes no host.
- runtime.server.ts, #2054: a compiled-only frame checks its output;
  ordinary frames keep the redesign's returned-value normalization.
- codes.json: main's 344-346 (CompiledContext, CompiledOutlet) keep their
  numbers; the redesign's codes move to 347 (server boundary error), 348
  (hydration protocol skew) and 349 (frontier rehome). Generated tables and
  CLI data are regenerated; docs/ssr.md names #348.

Adaptations:
- compiled-boundaries.test.ts: the server runs no error boundary (React's
  model), so an invalid CompiledOutlet under a catch-only @Try fails
  renderToString with the CompiledOutlet error; the client still shows the
  catch arm.
- scripts/render-writers.mjs drops resetOnlyChildHost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Compiler does not handle inline objects Compiler does not handle ref arrays

2 participants