Repository navigation
[collapsible][accordion] Expand hiddenUntilFound panels synchronously on beforematch - #5514
Conversation
…atch The browser removes `hidden` and measures the find-in-page match in the same task that dispatches `beforematch`, while the React state update only lands in a later one. Panels kept collapsed by persisted starting styles were still zero-sized at that point, so the match highlight was dropped even though the panel opened correctly. Drop those styles synchronously from the event handler so the panel geometry is correct before the browser measures. Co-Authored-By: Claude Fable 5 <[email protected]>
commit: |
Bundle size
PerformanceTotal duration: 1,115.88 ms -18.72 ms(-1.6%) | Renders: 76 (+0) | Paint: 1,862.15 ms -40.04 ms(-2.1%)
14 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…ored Removing `data-starting-style` imperatively desyncs the DOM from React, which renders the same prop for as long as the panel stays closed and therefore never rewrites the attribute. A controlled panel whose `onOpenChange` is ignored was left permanently expanded while still reporting `data-closed`. Put the attribute back on the next frame when the open state never arrived, once the browser has already measured the match. Also bind the handler to the same element the listener is attached to instead of re-reading the ref. Co-Authored-By: Claude Fable 5 <[email protected]>
`beforematch` marks the next open as motionless before it knows the open will happen. When a consumer declines that specific open, the mark survived and the following ordinary open lost its author-defined transition. Clear it alongside the restored collapsed styles, in the branch that already knows the open never arrived. Co-Authored-By: Claude Fable 5 <[email protected]>
The motion-skip reset only ran when the panel had persisted starting styles to restore, so keyframe panels — which stop carrying `data-starting-style` once the animation type is known — kept losing the next open's animation after an ignored reveal. Schedule the revert frame unconditionally and make only the attribute restoration conditional. The frame now also puts back `hidden="until-found"`, which the browser removes as part of the reveal and React never rewrites: without it, a canceled or ignored reveal left the panel out of the find-in-page index (and, for ignored transition panels, concealed only by `height: 0`) until the next open/close cycle. Canceled reveals schedule the same frame so the panel stays hidden and searchable, matching the cancellation intent. Co-Authored-By: Claude Fable 5 <[email protected]>
PR reviewBugs (1)1. ℹ️ If React's commit loses the race to the revert frame, a reveal degrades to pre-PR behaviorLocation: revertRevealFrame = AnimationFrame.request(() => {
if (latestOpenRef.current) {
return;
}
...The frame decides "the open never arrived" by reading Failure scenario: A page janking hard enough that a Fix: None needed now. If it ever surfaces, the frame can double-defer (schedule the check one frame later) or verify against a commit counter instead of a single ref read. VerdictApprove - all prior findings resolved and verified non-vacuously; the one remaining note is an unreachable-in-practice race whose failure mode is current production behavior. 🤖 Review generated with Claude Code |
…ming The revert frame read the committed open state at the next animation frame, which races React's scheduled commit: a rendering update can preempt the still-queued commit task and make the frame revert a reveal whose open was on the way. Decide in a task instead. `setOpen` has already scheduled React's work by the time the timeout is queued, so the decision drains after the commit even when a busy main thread delays both, and when the consumer ignores the open no commit is ever scheduled, so the decision holds. The DOM revert still runs in an animation frame so it stays atomic with respect to paint. Co-Authored-By: Claude Fable 5 <[email protected]>
PR reviewHead No findings. One residual, known and accepted rather than fixable: VerdictApprove - the decision race is closed by task ordering, every prior finding is resolved with non-vacuous coverage, and CI is green on the final head. 🤖 Review generated with Claude Code |
Closes #5513.
Expands
hiddenUntilFoundCollapsible and Accordion panels synchronously duringbeforematch, allowing Chrome and Safari to highlight find-in-page matches when transition CSS keeps the closed panel at zero height.If a controlled reveal is canceled or ignored, the panel restores its collapsed styles and
hidden="until-found"state without consuming the next normal opening animation.Covered by the Collapsible and Accordion suites in jsdom and Chromium, and manually verified in Chrome 151.