Repository navigation
fix(lab): write latest-value refs at commit, not during render - #10780
Conversation
Seven Lab files copied props or state into refs during render. A render React discards, as a suspended transition does, left its values there, and the next event read them. Post sent a draft the composer never showed, and an outside press dismissed a thread over an unsaved draft. A scroll gave the pull's edge back to the browser, and Add built on a selection the list never showed. Where the handlers own the value, they now read it from their own render and the ref is gone. Elsewhere a layout effect copies the value at commit. Two TransferList render reads use `value` directly.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC |
|---|---|---|
| lab/TransferList | 101.7 kB (+10 B) · 1.2 kB CSS (0) | — |
| lab/Comments | 351.3 kB (+9 B) · 2.5 kB CSS (0) | — |
| lab/CommentComposer | 152.1 kB (+6 B) · 1.9 kB CSS (0) | — |
3 more components
| Component | Size | LoC |
|---|---|---|
| lab/Schedule · Storybook | 106.3 kB (0) · 3.9 kB CSS (0) | 4,801 (−6) |
| lab/TransferListSelector | 109.2 kB (0) · 1.4 kB CSS (0) | — |
| lab/CommentThread | 344.4 kB (−4 B) · 2.4 kB CSS (0) | — |
Package size: no published package changed; no new dependencies.
API changes: none in this pull request
Committed API report behind this build: cli 29 rows, core 36 rows, theme-butter 1 row, theme-y2k 1 row; run pnpm api:report.
Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.
Generated by PR Enrichment workflow | View full report
There was a problem hiding this comment.
Requesting changes for one small cleanup. The rest of the fix holds up: the six new tests fail against main and pass on this branch.
- Drop the new
popoverReflayout effects inTimeGridView.tsx(lines 268–272) anduseScheduleViewPopover.ts(lines 92–96), as this PR already does foropenBlockRefandopenKeyRef, because every reader can usepopoverdirectly: the close effects run after every commit with that commit'spopover, and the frame callback needs only the stablepopover.contentRef.
[Automated review]
The close effects in TimeGridView and useScheduleViewPopover have no dependency list, so each runs after a commit with that commit's popover. The frame callback needs only popover.contentRef, one ref object for the hook's life. So the popover refs and the layout effects that copied them are gone.
|
/approve-spec d0fa87b |
There was a problem hiding this comment.
Approving: the popoverRef cleanup from the last review is in, and the six new tests fail against main and pass on this branch.
Approved pending CI: CI has not run on this head yet because the pull request is still a draft, and it runs once the pull request is marked ready for review.
One optional comment-wording suggestion is left inline.
[Automated review]
| // through this ref, as the composer's own listeners do. The ref is written | ||
| // at commit: a render React discards, as a suspended transition does, must | ||
| // not leave its draft for the listeners. |
There was a problem hiding this comment.
Non-blocking, missed last round: "The ref is written at commit" is passive, and the sentence carries two topics. Keeping only the reason:
// The document listeners run outside render and reach the latest draft
// through this ref, as the composer's own listeners do. A render React
// discards, as a suspended transition does, must not leave its draft for
// the listeners.
User impact
People using Lab's Comments, RefreshControl or TransferList in an app that renders with transitions. Seven files copied props or state into refs during render. A render React discards, as a suspended transition does, left its values in those refs, and the next event used them:
Problem and solution fit
A write during render runs for every render, including the ones React throws away. Handlers and listeners run later, against the committed screen, so they read values from a screen nobody saw. The person acts on what is shown, and the action uses something else.
Where a handler owns the change, or a reader can take the value from its own render, the ref is gone. Otherwise a layout effect copies the value at commit, since no handler sees the change: eight refs, in six effects. Every reader keeps its current read.
Expected behavior and authority
useRefcontract: do not writeref.currentduring rendering, except to initialize it.architecture:react-component-runtimeINV3 and INV4. Each new effect names what it syncs, acquires nothing, and can replay. No rendered value comes from a ref mutation.usePanGesturegot the same fix and the same suspended-transition test in fix(usePanGesture): write the onPan ref at commit #10090.Smallest restoration
Twelve writes in seven files. The table under Testing gives each one's shape and reason. No API, visual or default changes. In TransferList, two render reads of the ref now read
value, which that same render had just copied into it.Evidence
Scope
Testing
Each test renders the committed props, then re-renders new props in a transition that suspends for good. React keeps the committed tree and never commits that render. The test then acts on the committed screen.
CommentComposer.tsxlatestValueRefvalue. The host also sets it without any handler here, as when it clears the draft after a post.CommentComposer.tsxonActionPendingChangeRefCommentComposer.tsxisSubmittingRefisSubmitting. The host sets it as a post starts and ends, and no handler here sees that.useCommentThreadDismissal.tslatestRefdraft, which the thread derives from its controller's state during render. No handler in this hook seesdraftchange.refreshTouchController.tsisPullEnabledRefisDisabledprop for the scroll listener. No handler here sees it change.useRefreshControl.tsdispatchRefdispatchcallback, which no handler sets.dispatchkeeps one identity because its dependencies are all stable, so a discarded render wrote the same function. A probe over the hook's 66 tests saw one identity per hook.TimeGridView.tsxpositioningTimeGridView.tsxopenBlockRefopenBlockTimeGridView.tsxpopoverRefpopoverpopover.useScheduleViewPopover.tsopenKeyRefopenKeyopenBlockRef.openBlockRef.useScheduleViewPopover.tspopoverRefpopoverpopover. The frame callback needs onlypopover.contentRef, oneuseReffor the hook's life, now in that effect's dependencies.TransferList.tsxcurrentValueRefvalue.commit, the list's own change handler, already writes it. The layout effect covers the host's own changes, as a reset, which no handler here sees.pnpm exec vitest run packages/lab/src/{Comments,RefreshControl,Schedule,TransferList} --project ui: 16 files, 336 tests pass. On main, the six new tests fail.@astryxdesign/labtypecheck, source and docs: 0 errors. ESLint on the changed files: no new findings. One existing warning inCommentComposer.test.tsxis on main too.