[popups] Keep position transition running when the rendered side changes#5016
Draft
atomiks wants to merge 5 commits into
Draft
[popups] Keep position transition running when the rendered side changes#5016atomiks wants to merge 5 commits into
atomiks wants to merge 5 commits into
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,241.18 ms -76.40 ms(-5.8%) | Renders: 50 (+0) | Paint: 1,887.63 ms -105.62 ms(-5.3%)
10 tests within noise — details 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes animation bugs that occur when the rendered side changes while moving the popup between detached triggers (e.g. one trigger's popup fits below it, the other's flips above): the position jumped instead of transitioning, and the size morph snapped instead of animating. Same-anchor collision flips remain instant.
Position jump on anchor change
With a
Viewportpresent, theadaptiveOriginmiddleware expresses the position using the inset property nearest the anchor (bottomfor thetopside,rightfor theleftside, otherwisetop/left) so size transitions stay pinned to the correct edge. When the rendered side changes, the inset property swaps (e.g.bottom→top), and CSS can't interpolate fromauto, so the transition never starts and the popup snaps. Side changes that don't involvetop/leftkeep the same properties and animate fine, which is why it only happened "sometimes".Fix: the middleware tracks how each floating element was last positioned (inset pair, rendered side, dimensions, and anchor) in a
WeakMap. When the rendered side changes or the inset pair swaps, it commits an intermediate state before the new styles land, so the outcome doesn't depend on how updates batch within a frame:top→topstraight across the flip.Size morph snap
usePopupAutoResizeapplied the side-dependent anchoring styles inside its measurement effect, withanchoringStylesas a dependency. A rendered side change betweentopandbottom(orleftandright) changed that memo's identity, so the effect restarted: the cleanup cancelled the pending animation frame that would have started the size transition, and the re-run applied the already-committed new dimensions as the "previous" size — snapping the popup to the new size instantly.Fix: the anchoring styles are applied in their own effect, so a side change no longer restarts the measurement cycle and the in-flight width/height transition continues.
Bundle size
The middleware is now registered through the store by the
Viewportpart (replacing thehasViewportboolean) instead of being imported statically by each positioner, soadaptiveOriginis tree-shaken away unless aViewportis used.DEFAULT_SIDESmoved intouseAnchorPositioningso the positioning hook no longer pulls in the middleware module. Navigation Menu still imports it directly as before.Tests
popover-side-switchexperiment is included for manual verification of the combined behavior.Notes
One remaining (pre-existing) discontinuity: when the side flips mid-morph, the popup's pin within the positioner switches edges (
bottom: 0↔ static flow), so the popup can shift within the positioner box by the difference between the box height and the popup's current animated height at that moment. Smoothing that would require either transitioning the positioner's own width/height in demo CSS or compensating the pin swap, which is left out of scope here.