Skip to content

docs: document JSX values evaluating after the building call - #1369

Merged
trueadm merged 1 commit into
mainfrom
claude/sleepy-hodgkin-9b12b1
Sep 28, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/sleepy-hodgkin-9b12b1

Conversation

@trueadm

@trueadm trueadm commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Documents that a compiler-authored JSX value's non-literal props and children can run after the call that built it has returned, and pins that behavior with tests. No runtime or compiler change.

A test port found that a Lexical DecoratorNode whose decorate() returns <span>{this.getLabel()}</span> throws in $getState. Lexical calls decorate() while it reconciles an update with editor state active, and React evaluates this.getLabel() right there. Octane defers the child to render time (the stack runs through descNeedsBlocks). By then no editor state is active.

That deferral is intentional. #361 made JSX values resolve in their represented render scope, and the existing SharedDescriptorProviders tests pin it for host-only markup: one stored <span>{…}</span> rendered under two providers shows each provider's own value. The divergence doc framed this around providers and boundaries, though. It didn't say that plain markup is deferred too, or that values valid only during the building call are gone by render time.

Changes

  • docs/differences-from-react.md: new subsection "Values that exist only during the building call" under "JSX values follow the represented render scope". It covers the Lexical decorate() example and three fixes:
    • read the value into a local before building the JSX;
    • use createElement(...), which evaluates its arguments immediately;
    • pass a stable input such as the node key to a component that opens its own editor.read(...).
  • packages/octane/tests/scoped-jsx-values.test.ts and _fixtures/scoped-jsx-values.tsx: a ScopedDecorator fixture builds JSX inside a synchronous "active scope" and renders it in a different one. The inline form reads the render scope; the local and createElement forms read the build scope. These run for TSRX and TSX, client and server (24 cases across the dev and prod projects).

Validation

  • pnpm format:check
  • pnpm typecheck: not run. It doesn't cover packages/octane/tests (excluded in packages/octane/tsconfig.json). pnpm typecheck:files on the two test files shows three errors, and HEAD has the same three.
  • pnpm test: not run in full. CI covers it.
  • targeted tests: npx vitest run packages/octane/tests/scoped-jsx-values.test.ts passes (669 tests, both octane and octane-prod projects).
  • Seen failing: with deferral turned off in the compiler (jsxValueRootNeedsRenderScope / jsxValueChildrenNeedRenderScope returning false), all 8 inline cases fail and the local and createElement cases still pass.
  • pnpm react-parity:validate (includes the scan of this doc for misleading claims) passes. A local full pnpm react-parity:check exited 1 on a testing-library waitFor timer error in an upstream React test run. That run doesn't touch these files, but I didn't rerun it at the base to confirm.
  • No changeset: docs and tests only.

Risk / follow-ups

  • Separate inconsistency, being looked at elsewhere: a named function that returns JSX goes through isReturnJsxFunction, which evaluates its holes immediately. The same JSX from an arrow or a method is deferred. So a host-only element from function hostDecl() rendered inside <Ctx value="inner"> reads outer, and the arrow version reads inner, which contradicts the SharedDescriptorProviders contract. The new doc text says expressions "can run after", which stays true whichever way that is resolved.

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

Low Risk
Documentation and test coverage only; no production runtime or compiler behavior changes.

Overview
Documents and regression-tests that compiler-authored JSX stored in variables or props can evaluate non-literal children and props at render time, not while the building call (e.g. decorate()) is still on the stack—unlike React, which runs those expressions immediately.

Adds docs/differences-from-react.md subsection Values that exist only during the building call: plain host markup is deferred too; Lexical-style DecoratorNode.decorate() pitfalls; fixes (read into locals before JSX, createElement for immediate args, or defer reads to a child with editor.read(...)).

Adds ScopedDecorator fixtures and client + server tests for inline JSX (label from render scope), locals / createElement (label from build scope)—no compiler or runtime changes.

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

Compiler-authored JSX values defer their non-literal props and children to
the represented render scope (#361). The divergence doc framed this around
providers and boundaries, but it also covers host-only markup, so a value
that exists only while the building call runs is gone at render time. A
Lexical DecoratorNode whose decorate() returns <span>{this.getLabel()}</span>
throws in $getState because the label is read after Lexical's editor state
is no longer active.

Document the consequence with the Lexical example and the fixes: read the
value into a local, use createElement, or read from a component. Pin all
three forms in scoped-jsx-values for TSRX and TSX on client and server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent docs PR: documentation only labels Sep 28, 2026
@github-actions
github-actions Bot marked this pull request as draft September 28, 2026 15:22
@trueadm
trueadm marked this pull request as ready for review September 28, 2026 15:51
@trueadm
trueadm merged commit 4f868e3 into main Sep 28, 2026
57 checks passed
@trueadm
trueadm deleted the claude/sleepy-hodgkin-9b12b1 branch September 28, 2026 18:29
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 docs PR: documentation only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant