Skip to content

fix(useLayer): read committed callbacks and open state - #10912

Merged
cixzhang merged 3 commits into
meta:mainfrom
vjeux:fix/layer-refs-at-commit
Nov 12, 2026
Merged

cixzhang merged 3 commits into
meta:mainfrom
vjeux:fix/layer-refs-at-commit

Conversation

@vjeux

@vjeux vjeux commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Render-time ref writes fixed, each read in a callback: isOpenRef in useKeepLayerOpenProps, and onCloseStartRef and showRef in the layer runtime, all in core/Layer/useLayer.tsx. Red-first: yes, three new tests fail on main, one per ref.

User impact

People using a layer whose callbacks change between renders, with transitions. The layer kept its close-start callback, its replayed show and, for a control on its trigger, its open state in refs written while it rendered. A render React discards, as a suspended transition does, left its values there:

  • A show that waited for another layer's hide replayed with the discarded render's onShow. Popover and ContextMenu pass the public onOpenChange there.
  • A press on a keep-open control read the discarded open state. After a discarded render saying the layer was closed, it named no invoker. Selector and MultiSelector clear that state only after the layer hides, so this is preventive too.
  • A hide reported its close start to the discarded render's callback. Popover, the only caller, passes a stable function, so this is preventive.

Problem and solution fit

A write during render runs for every render, including the ones React throws away. Each is read after a commit.

The close-start callback now comes from useCommittedRef. The replayed show stays a plain ref for a callback declared above it, written by useCommittedRefInto. Both write at commit, before any layout effect that shows or hides the layer.

The keep-open press holds no ref now. Its handler reads the committed isOpen, or a layer already shown in the control's own tree. The runtime shows the layer before its open state commits.

Expected behavior and authority

  • React's useRef contract: do not write ref.current during rendering, except to initialize it.
  • architecture:react-component-runtime INV3 and INV17: a latest-value ref goes through useCommittedRef or its useCommittedRefInto form, and render writes no ref. INV4: no rendered value comes from a ref mutation.

Smallest restoration

Three refs in useLayer.tsx. No API, visual or default changes.

Evidence

  • Reproduction before the change: the three red-first tests fail on main 6ef8ba1, with the whole test file run.
  • Result after the change, at 1b6e941: they pass, with the guard.
  • Representative unchanged path: the existing show, hide and keep-open tests still pass.
  • Regression test or other mutation-sensitive proof: each red-first test fails while its ref is written during render.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

All runs below are at this PR's head, 1b6e941.

Each test commits one set of props, then renders others in a transition while a sibling suspends for good, so React never commits that render.

Ref Now Red-first test
onCloseStartRef useCommittedRef An open layer is closed with hide(): the committed onCloseStart is called, and the discarded one is not.
isOpenRef (useKeepLayerOpenProps) Removed: the handler reads the committed isOpen, or the shown layer After a discarded render that says the layer is closed, a press still names the control an invoker. Two guards cover a layer shown in a transition that has not committed, in the document and in a shadow root. They fail at f9d8b18 and at 2110306.
showRef A plain ref, written by useCommittedRefInto A show parked behind another layer's hide, after a discarded render with another onShow: the replay calls the committed onShow.
  • pnpm exec vitest run packages/core/src/Layer packages/core/src/Popover packages/core/src/Selector packages/core/src/MultiSelector packages/core/src/DropdownMenu packages/core/src/ContextMenu packages/core/src/Tooltip packages/core/src/HoverCard --project ui: 78 files, 2078 tests pass.
  • useLayer.test.tsx run whole against main's runtime: the three red-first tests fail, and the other 152 pass.
  • @astryxdesign/core typecheck: 0 errors. ESLint and Prettier on the changed files: clean.
  • The open #8125 touches this file elsewhere, and merges clean with this change.
  • History: the merge of main 6ef8ba1 on Nov 12 has one conflict, in useLayer.tsx, where main added two options beside the close-start callback. Both sides are kept. The next commit moves the two refs onto useCommittedRef and useCommittedRefInto.

@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 12, 2026 11:19am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 9, 2026
@astracat-bot

astracat-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 12, 2026, 11:35 AM UTC

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 1b6e941

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
LayerProvider 4.4 kB (0) · 20 B CSS (0) — ✓ · ✓ · ✗
lab/CommentComposer 156.5 kB (+91 B) · 1.9 kB CSS (0) — — · — · —
Link 55.2 kB (+84 B) · 7.1 kB CSS (0) — — · — · —
115 more components
Component Size LoC Visual · A11y · RTL
TabList 46.5 kB (+82 B) · 6.5 kB CSS (0) — — · — · —
SideNav 118.4 kB (+76 B) · 11.7 kB CSS (0) — — · — · —
TopNavHeading 80.3 kB (+73 B) · 11.6 kB CSS (0) — — · — · —
DropdownMenuSubMenu 73.2 kB (+72 B) · 10.1 kB CSS (0) — — · — · —
SideNavHeading 80.8 kB (+72 B) · 11.6 kB CSS (0) — — · — · —
StatusDot 32.9 kB (+72 B) · 5.4 kB CSS (0) — — · — · —
Toolbar 46.3 kB (+71 B) · 8.1 kB CSS (0) — — · — · —
lab/CommentThread 352.9 kB (+71 B) · 2.4 kB CSS (0) — — · — · —
SideNavItem 75.3 kB (+70 B) · 11.5 kB CSS (0) — — · — · —
AvatarGroup 47.8 kB (+69 B) · 5.8 kB CSS (0) — — · — · —
TopNav 75.8 kB (+69 B) · 11.3 kB CSS (0) — — · — · —
lab/ListInput 91.6 kB (+69 B) · 922 B CSS (0) — — · — · —
Selector 105.4 kB (+68 B) · 17.8 kB CSS (0) — — · — · —
Pagination 115.6 kB (+67 B) · 18.2 kB CSS (0) — — · — · —
Switch 106.9 kB (+67 B) · 10.0 kB CSS (0) — — · — · —
MultiSelector 99.8 kB (+66 B) · 17.2 kB CSS (0) — — · — · —
TopNavMenu 79.7 kB (+66 B) · 11.6 kB CSS (0) — — · — · —
NumberInput 75.1 kB (+64 B) · 11.8 kB CSS (0) — — · — · —
Typeahead 85.9 kB (+63 B) · 12.8 kB CSS (0) — — · — · —
ChatComposer 82.9 kB (+62 B) · 12.4 kB CSS (0) — — · — · —
Thumbnail 67.9 kB (+62 B) · 11.9 kB CSS (0) — — · — · —
richtext/RichTextEditor 301.8 kB (+62 B) · 2.6 kB CSS (0) — — · — · —
richtext/RichTextView 280.0 kB (+62 B) · 2.3 kB CSS (0) — — · — · —
charts/ChartTooltip 186.7 kB (+61 B) · 451 B CSS (0) — — · — · —
lab/TransferList 105.8 kB (+61 B) · 1.2 kB CSS (0) — — · — · —
BreadcrumbItem 89.9 kB (+60 B) · 12.5 kB CSS (0) — — · — · —
CheckboxList 71.9 kB (+60 B) · 7.8 kB CSS (0) — — · — · —
Avatar 44.9 kB (+59 B) · 5.6 kB CSS (0) — — · — · —
TableCell 114.5 kB (+59 B) · 18.2 kB CSS (0) — — · — · —
Tokenizer 102.1 kB (+59 B) · 19.5 kB CSS (0) — — · — · —
CodeBlock 78.7 kB (+58 B) · 11.6 kB CSS (0) — — · — · —
PowerSearch 300.1 kB (+58 B) · 24.7 kB CSS (0) — — · — · —
lab/Comments 359.6 kB (+58 B) · 2.5 kB CSS (0) — — · — · —
lab/Schedule 110.1 kB (+56 B) · 3.9 kB CSS (0) — — · — · —
ChatDictationButton 64.0 kB (+55 B) · 10.4 kB CSS (0) — — · — · —
TableHeaderCell 114.1 kB (+55 B) · 18.0 kB CSS (0) — — · — · —
DropdownMenu 102.5 kB (+54 B) · 17.9 kB CSS (0) — — · — · —
IconButton 63.5 kB (+54 B) · 10.3 kB CSS (0) — — · — · —
lab/ChatReactionBar 111.9 kB (+54 B) · 1.1 kB CSS (0) — — · — · —
Banner 65.5 kB (+53 B) · 10.8 kB CSS (0) — — · — · —
TableSelectionToolbar 73.7 kB (+53 B) · 13.6 kB CSS (0) — — · — · —
lab/DialogHeroHeader 86.6 kB (+53 B) · 372 B CSS (0) — — · — · —
ChatSendButton 63.9 kB (+52 B) · 10.3 kB CSS (0) — — · — · —
TextInput 71.1 kB (+52 B) · 11.5 kB CSS (0) — — · — · —
Tooltip 31.1 kB (+52 B) · 4.4 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 284.5 kB (+52 B) · 454 B CSS (0) — — · — · —
AlertDialog 109.3 kB (+51 B) · 15.0 kB CSS (0) — — · — · —
MobileNavToggle 63.8 kB (+51 B) · 10.3 kB CSS (0) — — · — · —
TopNavMegaMenu 74.5 kB (+51 B) · 12.2 kB CSS (0) — — · — · —
charts/Chart 209.6 kB (+50 B) · 516 B CSS (0) — — · — · —
Button 63.5 kB (+50 B) · 10.3 kB CSS (0) — — · — · —
CheckboxListItem 74.5 kB (+50 B) · 11.7 kB CSS (0) — — · — · —
ContextMenu 113.3 kB (+50 B) · 17.8 kB CSS (0) — — · — · —
Stepper 65.2 kB (+50 B) · 10.5 kB CSS (0) — — · — · —
TabMenu 77.1 kB (+50 B) · 11.5 kB CSS (0) — — · — · —
lab/ChatEmojiPicker 110.7 kB (+50 B) · 773 B CSS (0) — — · — · —
AvatarGroupOverflow 50.9 kB (+49 B) · 5.7 kB CSS (0) — — · — · —
Calendar 74.5 kB (+49 B) · 10.9 kB CSS (0) — — · — · —
ChatComposerInput 80.6 kB (+49 B) · 11.6 kB CSS (0) — — · — · —
ChatComposerTokenElement 80.6 kB (+49 B) · 11.6 kB CSS (0) — — · — · —
DialogHeader 66.3 kB (+49 B) · 11.8 kB CSS (0) — — · — · —
FieldLabel 54.3 kB (+49 B) · 5.7 kB CSS (0) — — · — · —
DrawerHeader 66.5 kB (+48 B) · 13.3 kB CSS (0) — — · — · —
ListItem 73.7 kB (+48 B) · 11.7 kB CSS (0) — — · — · —
Markdown 193.5 kB (+48 B) · 21.0 kB CSS (0) — — · — · —
MobileNav 74.1 kB (+48 B) · 11.0 kB CSS (0) — — · — · —
RadioList 59.6 kB (+48 B) · 7.3 kB CSS (0) — — · — · —
TextArea 65.6 kB (+48 B) · 9.4 kB CSS (0) — — · — · —
SideNavCollapseButton 64.4 kB (+47 B) · 10.4 kB CSS (0) — — · — · —
TimeInput 167.6 kB (+47 B) · 16.4 kB CSS (0) — — · — · —
Toast 101.3 kB (+47 B) · 10.6 kB CSS (0) — — · — · —
lab/DiffViewer 91.0 kB (+47 B) · 2.1 kB CSS (0) — — · — · —
MoreMenu 102.7 kB (+46 B) · 17.9 kB CSS (0) — — · — · —
ChatLayout 86.3 kB (+43 B) · 10.9 kB CSS (0) — — · — · —
ChatLayoutScrollButton 64.1 kB (+43 B) · 10.5 kB CSS (0) — — · — · —
DateRangeInput 97.6 kB (+43 B) · 12.9 kB CSS (0) — — · — · —
lab/CommentPin 59.3 kB (+42 B) · 1.2 kB CSS (0) — — · — · —
Field 58.2 kB (+41 B) · 7.3 kB CSS (0) — — · — · —
Table 130.4 kB (+41 B) · 18.7 kB CSS (0) — — · — · —
lab/TabBarMoreList 96.0 kB (+41 B) · 1.8 kB CSS (0) — — · — · —
lab/TransferListSelector 114.6 kB (+41 B) · 1.4 kB CSS (0) — — · — · —
CheckboxInput 67.7 kB (+40 B) · 10.1 kB CSS (0) — — · — · —
InfoTip 49.4 kB (+39 B) · 5.4 kB CSS (0) — — · — · —
ComplexSelector 75.9 kB (+38 B) · 12.2 kB CSS (0) — — · — · —
ToggleButton 90.2 kB (+38 B) · 10.4 kB CSS (0) — — · — · —
lab/SelectableCardGroup 67.6 kB (+38 B) · 162 B CSS (0) — — · — · —
RadioListItem 70.8 kB (+37 B) · 10.4 kB CSS (0) — — · — · —
InputGroup 59.9 kB (+36 B) · 7.9 kB CSS (0) — — · — · —
Slider 112.4 kB (+35 B) · 8.8 kB CSS (0) — — · — · —
lab/TourStep 101.7 kB (+35 B) · 590 B CSS (0) — — · — · —
DateInput 193.6 kB (+33 B) · 17.4 kB CSS (0) — — · — · —
HoverCard 29.3 kB (+33 B) · 4.4 kB CSS (0) — — · — · —
lab/EmojiPicker 90.4 kB (+31 B) · 751 B CSS (0) — — · — · —
AppShell 95.3 kB (+29 B) · 13.8 kB CSS (0) — — · — · —
DateTimeInput 216.1 kB (+29 B) · 19.1 kB CSS (0) — — · — · —
Lightbox 126.8 kB (+29 B) · 10.9 kB CSS (0) — — · — · —
FileInput 72.5 kB (+26 B) · 11.3 kB CSS (0) — — · — · —
BaseTypeahead 76.7 kB (+25 B) · 11.3 kB CSS (0) — — · — · —
SegmentedControl 100.2 kB (+23 B) · 6.9 kB CSS (0) — — · — · —
Carousel 73.2 kB (+22 B) · 11.3 kB CSS (0) — — · — · —
Popover 95.4 kB (+18 B) · 14.6 kB CSS (0) — — · — · —
ChatMessageList 29.9 kB (+1 B) · 7.1 kB CSS (0) — — · — · —
ProgressBar 12.0 kB (+1 B) · 6.4 kB CSS (0) — — · — · —
Spinner 26.5 kB (+1 B) · 6.2 kB CSS (0) — — · — · —
Timestamp 35.1 kB (+1 B) · 10.6 kB CSS (0) — — · — · —
Text 13.6 kB (0) · 5.5 kB CSS (0) — — · — · —
Timer 15.7 kB (0) · 6.0 kB CSS (0) — — · — · —
ChatToolCalls 34.1 kB (−1 B) · 8.4 kB CSS (0) — — · — · —
CommandPalette 75.2 kB (−1 B) · 12.7 kB CSS (0) — — · — · —
CommandPaletteInput 33.6 kB (−1 B) · 7.6 kB CSS (0) — — · — · —
charts/ChartLegend 53.8 kB (−2 B) · 224 B CSS (0) — — · — · —
Heading 14.1 kB (−2 B) · 5.5 kB CSS (0) — — · — · —
lab/LineClamp 15.7 kB (−2 B) · 168 B CSS (0) — — · — · —
layer — — — · ✓ · —
Layer — — ✓ · ✓ · —

Package size: @astryxdesign/core 7.38 MB packed (+256 B); no new dependencies.

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested: moving the three ref writes to commit is the right fix, and both new tests fail on main and pass here, but two things need to change first.

  • Popover is the only caller of onCloseStart and passes surfaceMotion.closeStart, which is the same function in every render, so please describe the close-start sync as preventive in the User impact section and reword the changeset (which also files the keep-open sync, used only by Selector and MultiSelector, under Popover, Tooltip, HoverCard and the menus), for example to "[fix] The layer runtime syncs its close-start, replayed-show and keep-open refs at commit, not during render, so a render React discards no longer leaves its values for later callbacks."
  • No test fails when the replayed-show sync (useLayer.tsx:1761-1766) goes back to the render-time write, so please add one beside the existing replay test that commits onShow A, discards a render with onShow B, replays the show and checks that only A runs.

Optional: split each insertion-effect comment into two sentences, one for what it syncs and one for why it runs before layout effects.

[Automated review]

Comment thread .changeset/layer-refs-at-commit.md Resolved
Comment thread packages/core/src/Layer/useLayer.tsx Resolved
Comment thread packages/core/src/Layer/useLayer.tsx Resolved
@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

/approve-spec f9d8b18

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested: the close-start and replayed-show syncs are right, and each new test fails on main and passes here, but the keep-open change needs another pass.

  • Miss: when a MultiSelector opens through handleRef inside a transition that has not committed, the list is shown while the committed isOpen is still false, so the press handler (useLayer.tsx:1157-1164) no longer names Clear all an invoker and pressing it closes the list, which stays open on main; please have the press read the layer's live open state (for example a getter over the runtime's own isOpenRef, which show and hide set beside the DOM call) and add a MultiSelector-level test for a show inside a pending transition.
  • Miss: the User impact section says a Selector or MultiSelector keep-open press could toggle the layer shut after a discarded render that said it was closed, but both pass the layer's own state, which turns false only after a hide has already hidden the layer (useLayer.tsx:1746-1752), so please describe the keep-open change as preventive for these callers or describe what the corrected fix changes.

Optional: await act(async () => runToggleTasks()) at useLayer.test.tsx:1537 removes the "act call was not awaited" warning that the replay test prints. CI has not run on this head yet; once the pull request is ready, a maintainer adds the ci:run label.

[Automated review]

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
});

// The hide ends at its toggle, and the parked show replays.
act(() => runToggleTasks());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: this synchronous act runs while the discarded transition is still pending, so React prints "A component suspended inside an act scope, but the act call was not awaited". await act(async () => runToggleTasks()); keeps the test log clean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kept the synchronous act here on purpose: with await act(async () => runToggleTasks()) this test passes on main (the whole file then fails 2 tests on main, not 3), so it no longer catches the render-time showRef write. The synchronous form keeps it red on main and green at this head.

@vjeux vjeux changed the title fix(useLayer): sync its callback refs at commit fix(useLayer): read committed callbacks and open state Nov 10, 2026
@vjeux
vjeux force-pushed the fix/layer-refs-at-commit branch from f9d8b18 to 2110306 Compare November 10, 2026 00:01
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 2110306

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested: the close-start and replayed-show syncs are right, and each red-first test fails on main and passes here, but two things need to change.

  • The keep-open press finds the layer with ownerDocument.getElementById (useLayer.tsx:1162), so a Selector or MultiSelector inside a shadow root that opens in a pending transition closes when its Clear all control is pressed, where main keeps it open; look the layer up in control.getRootNode() instead and add a shadow-root case to the pending-show test.
  • The description's keep-open user impact still names Selector and MultiSelector users for a discarded render that says the layer is closed, but both callers' open state turns false only after the layer is already hidden, so please mark that part preventive as the close-start bullet is.

A non-blocking comment-wording suggestion is inline.

[Automated review]

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
Comment thread packages/core/src/Layer/useLayer.tsx Resolved
The layer kept its close-start callback, its replayed show and, for a
control on its trigger, its open state in refs written while it
rendered. A render React discards, as a suspended transition does,
left its values there. A hide then reported its close start to the
discarded render's callback, and a press on a keep-open control read
the discarded open state.

The two the layer calls from its own show and hide sync in insertion
effects, ahead of any layout effect that shows or hides the layer in
that commit. The keep-open press holds no ref now. It reads the
committed open state, or a layer the runtime already shows ahead of
that state.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved pending CI: CI has not run on this head yet; it runs once the pull request is marked ready for review and a maintainer adds the ci:run label.

The two commit-time ref syncs and the tree-scoped keep-open lookup fix the earlier findings, and each ref has a red-first test that fails on main.

  • Non-blocking: no test pins the insertion timing; layout or passive effects also pass every useLayer test.
  • The earlier suggestion to await the replay test's act is withdrawn: awaiting it lets that test pass on main.

[Automated review]

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 90fa9a1

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 10, 2026
The hide's close-start callback now comes from useCommittedRef, listed
in the deps of the two callbacks that read it. The replayed show stays
a plain ref, since a callback declared above it reads it, and
useCommittedRefInto writes it. Both write at commit, before any layout
effect, as the insertion effects they replace did.
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 1b6e941

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved pending CI: CI has not run on this head yet; it runs once the pull request is marked ready for review.

The close-start and replayed-show refs now go through the shared commit-time hook, the keep-open press reads the committed open state or the shown layer, and each ref has a red-first test. There are no blocking findings.

Claims and files checked
  • Claims:
    • The changeset's fix (close-start and replayed-show refs synced at commit; keep-open press reads the committed open state or the shown layer): verified in useLayer.tsx.
    • Three render-time ref writes are removed, one per ref: verified.
    • Popover and ContextMenu pass onOpenChange through onShow: verified.
    • Popover is the only close-start caller and passes a stable function, so that case is preventive: verified.
    • Selector and MultiSelector pass the layer's own open state, so the discarded-closed keep-open case is preventive: verified.
    • Both refs are written at commit, before any layout effect: verified (the shared hook's insertion effect).
    • The runtime shows the layer before its open state commits: verified.
    • Three red-first tests fail on main, one per ref: consistent with the code, since each asserts the value main's render-time write replaces; CI confirms the run.
    • The two guards fail at the earlier heads: consistent with those heads' press handlers.
    • No API, visual or default change: verified.
    • The related suites, typecheck and lint pass: CI confirms these.
    • The open #8125 merges cleanly with this change: verified.
    • The merge of main kept both sides of its one conflict, and the next commit moves the two refs onto the shared hook: verified.
  • Files:
    • .changeset/layer-refs-at-commit.md: clear.
    • packages/core/src/Layer/useLayer.tsx: clear.
    • packages/core/src/Layer/useLayer.test.tsx: clear.

Automated review (maintainer link)

@vjeux
vjeux marked this pull request as ready for review November 12, 2026 12:17
@cixzhang
cixzhang merged commit 1dbbc73 into meta:main Nov 12, 2026
134 checks passed
@vjeux
vjeux deleted the fix/layer-refs-at-commit branch November 12, 2026 13:09
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 12, 2026
Main brings in meta#10912, which changes Layer/useLayer.tsx, the layer the
mode hint shows. The merge needs no hand edit.
cixzhang pushed a commit that referenced this pull request Nov 12, 2026
…10815)

* refactor(List): write the reorder refs at commit, not in render

Conformance tidy, no visible change. The reorder session's list getter
and the mode hint's layer handle were copied into refs during render.
Each is now written in a one-line layout effect, so a render React
discards leaves nothing behind. No failure is reachable today. Every
list getter returns the same element. The layer ref's only reader is
the hint's layout effect. It reads the ref at the commit, right after
the committed render wrote it. The cleanup uses the handle it captured.

* fix(List): a reorder handle's name follows its row's place and label

A reorder handle named itself from the DOM in a passive effect: after
Item's label element when that element shows a name, else after the
row's place ("Reorder item N"). The effect ran only when the handle
rendered. A memoized row whose place changed, because a row above it
went or the rows reordered, kept the old place in its handle's name. A
label that gained or lost its text through its own state left the
handle named the old way.

The reorder session now reads both from the DOM, outside React. It
registers the list's rows and its handles' label elements with Core's
shared mutation observer, and releases them with the list. It keeps
each handle's label naming, and the place only for a handle named after
it. The handle reads them through useSyncExternalStore, as it reads
reorder mode, and renders its name from them. Only a change renders
the handle again, so its passive effect is gone. A row named after its
place still warns in development, once, from the session. positionOf
loses its last caller and goes.

The session follows the list element the List renders, which changes
when its numbering turns on or off.

ListReorderNames.test.tsx covers a row above that goes, a reorder, and
a label that gains and loses text: each fails on main and passes here.
A reorder after the numbering turns on passes on both.

* Merge main 1740654 into the reorder handle names

Main brings in #11199, whose controller reads a collection's rows
through a reader, and #11352's committed-ref hook. #11199 edits
positionOf, which this branch removes; it stays removed. One hand edit:
refreshNames reads this.rows.read(list) instead of rowsOf(list), as
#11199's positionOf did, so a collection's own reader numbers its rows.

* refactor(List): the reorder refs use the committed-ref hook

The session's list getter and the mode hint's layer handle were each
copied into a ref by a one-line layout effect. They now use Core's
useCommittedRef, which writes them in a commit-phase insertion effect.
The session's useMemo lists the stable getter ref in its dependencies.

No behavior changes. Every getter List passes reads the same list ref
when called, and the hint's effect reads the handle after either
write. A handle's cleanup can reach the getter through release(), and
gets the same list. The hint's cleanup hides the handle its setup
showed, so no cleanup reads the layer ref.

* fix(List): an unchanged handle name keeps its snapshot

The names refresh compared each handle's name with the session's own
entry, which a handle named some other way has none of before the
first read. So it stored a new {position: null, labelNamesRow: null}
and the handle rendered again with the same name on every mount
(architecture:react-component-runtime INV9). It now compares with
handleNameOf, whose shared unread name has the same fields.

A test counts the handle's renders through the verb it reads each
render: once per handle on mount, and once for a row that mounts later.

* fix(List): a hydrated handle keeps its server snapshot

The handle's server snapshot was its own unread name, and the session
answered an unread handle with another object with the same fields.
So after hydration React saw a new snapshot, and each handle rendered
again with the same name (architecture:react-component-runtime INV9).
The handle now exports one unread name, and the session answers with
it.

A test hydrates server markup and counts the handle's renders through
the verb it reads each render: once per handle.

* fix(List): a label that names its row keeps the unread snapshot

The names refresh stored whether Item's label element names the row:
null before the first read, and true after it, though the handle and
the session read both alike. So a handle named by its row's text label
rendered again with the same name after mounting and after hydrating
(architecture:react-component-runtime INV9). The snapshot now records
whether the label shows no name, which stays false until a read finds
the label blank.

Both render-count cases add a row named by its text label.

* Merge main 06b7e61 into the reorder handle names

Main brings in #10912, which changes Layer/useLayer.tsx, the layer the
mode hint shows. The merge needs no hand edit.

* Merge main 31aacff into the reorder handle names

Main brings in #11336, which changes List/ListItem.tsx, the row that
renders the reorder handle. The merge needs no hand edit.

This branch was successfully deployed

1 active deployment
Preview — 1b6e941e Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants