fix(anchor): eliminate position flash by switching to useLayoutEffect#299
Open
draedful wants to merge 1 commit into
Open
fix(anchor): eliminate position flash by switching to useLayoutEffect#299draedful wants to merge 1 commit into
draedful wants to merge 1 commit into
Conversation
useEffect fires after paint, causing anchors to briefly appear at their default position before snapping to the correct coordinates. Replace with useSignalLayoutEffect (new synchronous variant) so the CSS variables are applied before the browser paints the frame. Also hide anchors whose position has not yet been calculated by defaulting the CSS fallback to -99999px instead of 0px.
Reviewer's GuideIntroduces a layout-effect-based signal hook and uses it to apply anchor position styles synchronously, while changing default anchor CSS to hide unpositioned anchors off-screen instead of at (0,0). File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
|
Preview is ready. |
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.
Summary
useSignalLayoutEffect— synchronous variant ofuseSignalEffectthat runs viauseLayoutEffectinstead ofuseEffectuseBlockAnchorPositionto use it so CSS variables are applied before the browser paints-99999pxso anchors without a calculated position are hidden off-screen instead of appearing at0,0Problem
useEffectfires asynchronously after the browser paints, causing anchors to flash at their default position (0px, 0px→ top-left corner of the block) for one frame before snapping to the correct coordinates. The position was already known at render time — it just wasn't applied synchronously.Test Plan
npm test)Summary by Sourcery
Prevent block anchors from briefly rendering at an incorrect position by making their position updates synchronous and hiding them off-screen until coordinates are available.
New Features:
Bug Fixes:
Enhancements: