Repository navigation
docs(react-component-runtime): latest-value ref sync and render-time ref writes - #10161
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Approval waits on an engineering owner's decision on the proposed architecture:react-component-runtime changes: INV3's new lead sentence, INV3's one-line layout or insertion Effect exception, the new INV17, and their verification rows. An engineering owner records it by commenting /approve-spec with the full head commit SHA on this pull request. The author may do this, as an engineering owner.
These need fixing whatever the decision:
- INV3's new lead sentence ("no Effect reacts to interaction state") has no stated limit, so read literally it forbids Effects that INV2 still allows, such as ContextMenu's outside-press listener while open (
ContextMenu.tsx:521) and DropdownMenu's focus move after a keyboard open (DropdownMenu.tsx:676-711); say which Effects it means. - "
useEffectEventreplaces it once Core's React floor reaches 19.2" does not hold for refs read outside Effects: React allows an Effect Event to be called only from Effects, and these refs are read from handlers, callback-ref listeners and hook models (useTooltip.tsx:715-746,Slider.tsx:972-975); limit the clause to that case or remove it. - INV17's known-gap list names three files, but 59 Core and Lab files write a ref during render (for example
useLayer.tsx:1022,useFocusTrap.ts:519and the Table plugin hooks); state the gap as a class with examples, as INV16's gap does.
Optional: a concerns pattern for .current = writes would route INV17 for a change that only adds one.
[Automated review]
| - **INV3 — Effects synchronize external systems.** Interaction logic lives in | ||
| callbacks; no Effect reacts to interaction state. A new or changed Effect MUST |
There was a problem hiding this comment.
"No Effect reacts to interaction state" has no stated limit, so it also forbids Effects that INV2 still allows: ContextMenu's outside-press listener while isOpen (ContextMenu.tsx:521) and DropdownMenu's focus move after a keyboard open commits (DropdownMenu.tsx:676-711). Consider: "no Effect decides from interaction state what an interaction does (show, hide, open, close, focus, reset); an Effect may subscribe to an external system while that state holds, or do post-commit work the handler already decided (INV2)."
…f-sync # Conflicts: # docs/architecture/react-component-runtime.md
There was a problem hiding this comment.
Approval waits on an engineering owner's decision on the proposed architecture:react-component-runtime changes: INV3's new lead sentence, its one-line layout or insertion Effect exception, the new INV17, and their verification rows. An engineering owner records it by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.
These need fixing whatever the decision:
- INV3's new lead sentence ("no Effect reacts to interaction state") has no stated limit, so it forbids Effects that INV2 still allows, such as ContextMenu's outside-press listener while open (
ContextMenu.tsx:521) and DropdownMenu's focus move after a keyboard open (DropdownMenu.tsx:676-711); say which Effects it means. - "
useEffectEventreplaces it once Core's React floor reaches 19.2" does not hold for refs read outside Effects, because React allows an Effect Event to be called only from Effects and never passed down, while these refs are read by callback-ref listeners, a hook model and an imperative handle (useTooltip.tsx:724,Slider.tsx:1293,ChatComposerInput.tsx:503-505); limit the clause or remove it. - INV17's gap note names three files that write latest-value refs, but 61 Core and Lab files write a ref during render, some to track a previous value or count renders (
useLayer.tsx:1022,Markdown.tsx:2243-2250,useTooltip.tsx:322-324); state the gap as a class with examples, as INV16's gap does.
Optional: a concerns pattern for .current = writes would route INV17 for a change that only adds one.
[Automated review]
…k, useCommittedRef (DEC-3)
|
/approve-spec fbfa599 |
… Effect; sortable header read is a known gap
|
/approve-spec 7b75174 |
|
/approve-spec d248954 |
There was a problem hiding this comment.
Changes requested: an engineering owner approved this head's direction for architecture:react-component-runtime, so four text fixes remain, three in the record and one in the description, and a record fix makes a new head that needs a new /approve-spec.
- Regression: INV17 allows a render-time
ref.currentwrite only for lazy one-time initialization and names only Toast as an exception, which contradictscomponent:MarkdownDEC-7 and this record's INV4: both keep Markdown's render-time fade-in refs and reject syncing them at commit, so add that exception to INV17 or amend DEC-7. - INV3 and DEC-3 say
useEffectEventreplacesuseCommittedRefat React 19.2, but React allows an Effect Event to be called only from Effects or other Effect Events, and INV3 lets only event and gesture callbacks read these refs, so drop the clause or limit it to callbacks that only an Effect calls. - The INV3 (ref sync) verification row's failure signal still lists the old per-site Effect conditions ("a ref-sync Effect with logic or without a note", "a plain
useEffectused for the sync"), so a one-line, noted layout-Effect sync that INV3 now forbids matches no listed signal; make the failure any per-site Effect or render-time write in place ofuseCommittedRef, or a read of one during render or inuseMemo. - The description's Decision, Claim scope and Rejected alternatives sections still describe the superseded one-line Effect exception and leave out DEC-3, the
useCommittedRefentry, the Toast exception and theuseTableSortablegap, so update them to match the head.
Non-blocking: limit DEC-3's ordering sentence to layout-Effect setups, because a descendant's layout-effect cleanup runs before the insertion Effect, as the Toast exception says. Also restate the INV17 fix order and the "not on main yet" and "not built yet" lines as INV17 gaps (rubric R7).
Claims and files checked
- INV3 opens with "interaction logic lives in callbacks": verified (record lines 126-127).
- INV3 gains an exception for a one-line layout or insertion Effect: false; INV3 now forbids any per-site Effect copy (line 136).
- New INV17 forbids render-time ref writes except lazy initialization: verified (lines 393-394).
- The verification rows say item j flags the allowed form and misses insertion Effects, and that nothing flags render-time writes: partly false; the INV3 row now says item j does not yet recognize the hook (line 606), and the INV17 row's gap is accurate (line 618).
- INV17 lists ChatComposerInput, Slider and useTooltip as gaps: verified, as examples of about 70 writers (lines 401-403).
- The scope is only the INV3 exception, INV17 and their rows: false; the head also adds DEC-3, an Owning code entry, the Toast exception and the
useTableSortablegap. - No code changes: verified (one record file).
- No rejected alternatives: false; DEC-3 records one (lines 587-588).
- Core's React floor is 19.0: verified (
packages/core/package.json:934). - The hook sits beside the internal isomorphic layout Effect hook and is never exported: verified as recorded;
useIsomorphicLayoutEffectexists and is not exported fromhooks/index.ts. - A commit-phase write survives a discarded render,
useEffectEventneeds 19.2, and the insertion Effect skips the server, works on React 18 and later, and runs before refs attach: verified against React's documentation. - The insertion Effect runs before every layout Effect in the commit: true for setups only (non-blocking note).
- The sortable header read stays a gap because the plugin is documented as stable: verified (
useTableSortable.tsx:345,:368-369,:382). - No React floor change: verified.
- Writing rubric: no narration, research, change references or long rejected alternatives: verified; the R7 project-status result is missing.
docs/architecture/react-component-runtime.md(the only changed file): the four findings and two notes above.
…vent scope, INV3 failure signal
|
/approve-spec 4d96110 |
There was a problem hiding this comment.
Changes requested: an engineering owner approved this head's direction for architecture:react-component-runtime and the four earlier fixes are in, so one record fix remains; that fix makes a new head, which needs a new /approve-spec.
- Miss: the INV17 verification row fails any render-time
ref.currentwrite outside a lazy one-time initialization and any behavior that reads a discarded render's value, which fails Markdown's streaming fade-in refs thatcomponent:MarkdownDEC-7, INV4 and INV17's own exception keep, so add "or an exception INV17 names" to both clauses of its failure signal.
Non-blocking: drop the work order and build status from INV17 and the Owning code entry ("fixed in this order", "not built yet") and keep each gap as INV17 gap: <observable mismatch>. Name the internal entry point Lab imports useCommittedRef from, since the record governs Lab and keeps the hook out of hooks/index.ts. The description's owner-decision paragraph should say the insertion Effect runs before every layout-Effect setup, as the record now does.
Claims and files checked
- The current record has no ref-sync exception and no rule on render-time ref writes: verified (base record).
- The pre-review tool flags an Effect that only copies into a ref and an Effect with no system note: verified (
scripts/lib/pre-review-findings.mjs:222,:229). - Core's React floor is 19.0: verified (
packages/core/package.jsonpeer range). - INV3 opens with "interaction logic lives in callbacks": verified (lines 126-127).
- Latest-value refs go only through the internal hook, are read only in callbacks, and
useEffectEventapplies only where an Effect alone calls the callback: verified (lines 133-140). - INV17 forbids render-time writes except lazy initialization, keeps the Markdown and Toast exceptions and lists the gaps: verified (lines 393-412).
- DEC-3 records the hook choice, the concurrency check and the rejected per-component Effect: verified (lines 568-592).
- The Owning code entry places the hook beside
useIsomorphicLayoutEffectand keeps it unexported: verified (lines 545-550;hooks/index.tsexports neither). - The INV3 row accepts only the hook: verified (line 610). The INV17 row reviews render-time writes: verified (line 622), but its failure signal leaves out INV17's exceptions (the finding above).
- The change is record-only, with no code and no React floor change: verified (one changed file).
- ChatComposerInput, Slider and
useTooltipwrite latest-value refs during render: verified (ChatComposerInput.tsx:640-642,Slider.tsx:1022,useTooltip.tsx:323). - A commit-phase write survives a discarded render,
useEffectEventneeds React 19.2, and the insertion Effect works on React 18 and later, skips the server and runs before refs attach: verified against React's documentation. - The insertion Effect runs before every layout Effect in the commit: true for layout-Effect setups only (non-blocking).
- The sortable header read stays a gap because the plugin is documented and tested as stable: verified (
useTableSortable.tsx:345,:369,:382;useTableSortable.test.tsx:520). - The gap counts (three reads, about 70 writers, about 18 previous-value reads): match the record; not counted site by site.
- Writing rubric results R1-R6: verified; there is no temporary-status result, and the record carries status lines (non-blocking).
- The knowledge check, Prettier and whitespace check: not reproduced at this head.
docs/architecture/react-component-runtime.md(the only changed file): the finding and the non-blocking notes above.
…ptions; gaps as observable mismatches; Lab's internal entry
|
/approve-spec 6228f92 |
There was a problem hiding this comment.
Changes requested: an engineering owner approved this head's direction for architecture:react-component-runtime and the last review's four fixes are in, so one record fix remains.
- Miss: INV3 now forbids a per-site Effect that copies a latest value into a ref (
react-component-runtime.md:136), but the record has no gap line for the about 45 such Effects in Core and Lab today (for exampleLayer/useLayerDismissal.ts:164-168,hooks/useHotkeys.ts:156-158,ComplexSelector/ComplexSelector.tsx:804-806), so add anINV3 gap:line for them, as INV17 does for render-time writers.
Non-blocking: the two "does not exist yet" gap lines (:409-410, :550) state build status instead of an observable mismatch, DEC-3's quoted answer keeps this pull request's number (:572), and the description still calls INV17's gaps ordered. The record fix makes a new head, which needs a new /approve-spec <full head SHA> from an engineering owner; the author may comment it as one.
Claims and files checked
- Claim: the current INV3 has no latest-value ref exception and no invariant covers render-time ref writes — verified against the base record.
- Claim: the pre-review item j flags an Effect that only copies a value into a ref — verified (
scripts/lib/pre-review-findings.mjs:222). - Claim: Core's React peer floor is 19.0, so
useEffectEventis unavailable — verified (packages/core/package.json). - Claim: INV3 gains the callbacks lead and the hook-only latest-value ref rule, read only in event and gesture callbacks — verified (
react-component-runtime.md:126-140). - Claim: new INV17 with the Markdown and Toast exceptions and five gaps — verified (
:393-410). - Claim: DEC-3 records the owner's choice, the concurrency check and the rejected per-component Effect — verified (
:568-592). - Claim: the hook is internal, never in the hooks index, and Lab reaches it through a Core internal entry — verified (
:543-550). - Claim: the two verification rows accept only the hook and review render-time writes — verified (
:610,:622). - Claim: no code changes, and the hook, the item j recognition and the affected components are recorded gaps — partly false: no code changes, but the per-site Effect copies are not recorded.
- Claim: ChatComposerInput, Slider and useTooltip write refs during render — verified (
ChatComposerInput.tsx:640-641,Slider.tsx:1022,useTooltip.tsx:323). - Claim: the insertion Effect runs before every layout-Effect setup, keeps the initial value on the server, works on React 18 and stores values only — verified against React's documented contract and
:582-590. - Claim: INV17's gaps are ordered — the record states no order at this head (non-blocking).
- Claim: the table sorting header read is a gap that needs a Table API choice — verified (
useTableSortable.tsx:345,:368-369,:382). - Claim: writing rubric results R1-R6 — R5 misses the pull request number in DEC-3, and no R7 result is given (non-blocking).
- File:
docs/architecture/react-component-runtime.md— one blocking finding and three non-blocking notes.
…aps state observable mismatches
|
/approve-spec 2b642c3 |
|
Decision: D-20261112-109 |
There was a problem hiding this comment.
Approved pending CI: an engineering owner approved this head's architecture:react-component-runtime changes, and the last review's one blocker is fixed, since INV3 now records the existing per-site Effect copies (react-component-runtime.md:141-143). CI's build and test jobs were cancelled at this head because CI was full, so they need a re-run before this can merge.
Non-blocking: the Owning code sentence "Until it exists, …" (:553-554) and the INV3 row's "does not yet recognize" (:614) still state build status, which architecture:knowledge-contracts INV32 keeps out of records; DEC-3's "option A" (:576) names an option list the record does not hold; and the description's rubric results have no R7 line.
Claims and files checked
- Claim: current INV3 has no latest-value ref exception and no invariant covers render-time ref writes — verified against the base record.
- Claim: the pre-review check flags an Effect that only copies a value into a ref — verified (
scripts/lib/pre-review-findings.mjs:222). - Claim: Core's React peer floor is 19.0, so
useEffectEventis unavailable — verified (packages/core/package.json:934). - Claim: INV3 gains the callbacks lead and the hook-only latest-value ref rule, read only in event and gesture callbacks — verified (
react-component-runtime.md:126-140). - Claim: INV3 records about 45 existing per-site Effect copies as a gap — verified (
:141-143; 45 such Effects at this head). - Claim: new INV17 with the lazy-initialization, Markdown and Toast exceptions and its gaps — verified (
:396-413;ToastViewport.tsx:399,useTableSortable.tsx:368-382). - Claim: DEC-3 records the owner's choice of one shared hook, the concurrency check and the rejected per-component Effect — verified (
:572-596). - Claim: the hook is internal, never in the hooks index, and Lab reaches it through a Core internal entry — verified (
:546-554). - Claim: the two verification rows accept only the hook and review render-time writes — verified (
:614,:626). - Claim: no code changes, and the hook, the pre-review recognition and the affected components are recorded gaps — verified (one file;
:141-143,:400-413,:614). - Claim: ChatComposerInput, Slider and useTooltip write refs during render — verified (
ChatComposerInput.tsx:640-642,Slider.tsx:1022,useTooltip.tsx:323). - Claim: the insertion Effect runs before every layout-Effect setup, keeps the initial value on the server, works on React 18 and stores values only — verified against React's documented contract and
:586-593. - Claim: the record states observable behavior and preserves equivalent implementations — does not hold for INV3's ref clause, which names one internal hook on purpose; the named-mechanism checklist item applies, and DEC-3 gives the reason.
- Claim: writing rubric results R1-R6 — hold; no R7 result is given (non-blocking).
- Claim: validated with the knowledge check, Prettier and the whitespace check — verified (both pass in Lint at this head; the whitespace check is clean).
- File:
docs/architecture/react-component-runtime.md— no blocking finding; three non-blocking notes.
| internals. Until it exists, sites keep the per-site Effect copies INV3's gap | ||
| lists. |
There was a problem hiding this comment.
Non-blocking: "Until it exists" says the hook is not built yet, and architecture:knowledge-contracts INV32 keeps build status out of every section of a record. INV3's gap (lines 141-143) already records the per-site Effect copies, so this sentence can go. The INV3 (ref sync) row's "item j does not yet recognize useCommittedRef" (line 614) has the same "yet"; "item j does not recognize useCommittedRef" states the mismatch.
|
|
||
| **Decider:** `cixzhang`, `2026-11-11` | ||
|
|
||
| The owner chose option A, "one shared internal hook (useCommittedRef)": |
There was a problem hiding this comment.
Non-blocking: the record lists no options, so "option A" points at a list that lives only in this pull request's conversation, while architecture:knowledge-contracts INV10 has a record stay complete without the pull request. Suggest: "The owner chose one shared internal hook: latest-value refs use …".
Exact decision needed
How
architecture:react-component-runtimetreats two ref patterns that review keeps raising: an Effect that only keeps a ref at the latest committed prop or callback for event or gesture callbacks, and aref.currentwrite during render.Existing authority searched
architecture:react-component-runtimeINV2 (discrete intent stays discrete), INV3 (Effects synchronize external systems) and INV4 (mutable refs do not become hidden rendered state). INV3 names no exception for a latest-value ref sync, and no invariant covers render-time ref writes.pnpm review:preitem j (scripts/lib/pre-review-findings.mjs): "The Effect only copies a value into a ref" and "The new Effect has no note that names the system it syncs".packages/core/package.jsonpeerreact >=19.0.0), souseEffectEventis not yet available to Core.Decision
useCommittedRef(DEC-3), which writes it in a commit-phase insertion Effect. No per-site Effect copy and no render-timeref.current =write. Such a ref is read only in event and gesture callbacks, never during render or inuseMemo; render reads the value directly. Where only an Effect calls the callback,useEffectEventreplaces the hook once Core's React floor reaches 19.2. INV3 gap: about 45 per-site Effect copies today.ref.currentduring render, except a lazy one-time initialization. Exceptions: Markdown's streaming fade-in refs (component:MarkdownDEC-7, INV4), and Toast's earlier-siblingToastRefSync(a child's layout-Effect cleanup can calltoast()before the viewport's insertion Effect). INV17 gaps: three render-time reads of a latest-value ref;useTableSortable's header read (needs a Table API choice); about 70 render-time writers; about 18 previous-value reads; ToastViewport writes its toast list during render.packages/core/src/hooks/useCommittedRef.ts, internal, never inhooks/index.ts; Lab imports it from@astryxdesign/core/internal/committed-ref.useMemoread; INV17's row reviews render-time writes.Rejected alternatives
Claim scope and non-goals
INV3, INV17, DEC-3, one Owning code entry, and the INV3 and INV17 verification rows. No code changes: the hook, the review:pre recognition of it, and the listed components are recorded gaps. No React floor change.
Evidence and implementation relationship
Current source: review:pre item j's rules, and render-body
ref.currentwrites in ChatComposerInput, Slider anduseTooltip. No implementation PR.Owner decision
The owner answered "10161 A" (
cixzhang, 2026-11-11), recorded asarchitecture:react-component-runtimeDEC-3: latest-value refs go only through one internal hook,useCommittedRef<T>(value: T): { readonly current: T }, inpackages/core/src/hooks/useCommittedRef.tsbesideuseIsomorphicLayoutEffect, never exported fromhooks/index.ts. Itscurrentis written only in a commit-phase insertion Effect (it stores values only, never DOM nodes, since refs are not attached yet when it runs). INV3 forbids reading these refs during render or inuseMemo; those sites read the value directly. INV17 lists its gaps as observable mismatches: three render-time reads of a latest-value ref,useTableSortable's header read (needs a Table API choice), about 70 render-time writers, about 18 previous-value reads, and ToastViewport's render-time list write. INV3 lists about 45 per-site Effect copies as its gap. Her question on concurrent rendering was checked: a commit-phase write survives a render React drops, a render-phase write does not, anduseEffectEventneeds React 19.2 or later. The insertion Effect runs before every layout-Effect setup in the same commit, server rendering keeps the initial value, and it works on React 18 and later. No React floor change.Writing rubric results
Scope
Validation
pnpm check:knowledgegit diff --check