perf(usePositionFixed): rewrite to use ScrollTimeline Web Animations API#4091
Closed
perf(usePositionFixed): rewrite to use ScrollTimeline Web Animations API#4091
Conversation
Agent-Logs-Url: https://github.com/cybersemics/em/sessions/a181a523-4c64-47fe-8cea-7bd5c5d1cd9a Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
…Scroll) in animation, use clientHeight for maxScroll Agent-Logs-Url: https://github.com/cybersemics/em/sessions/a181a523-4c64-47fe-8cea-7bd5c5d1cd9a Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
raineorshine
April 11, 2026 01:27
View session
Contributor
|
Still jittery |
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
Rewrites
usePositionFixed.tsto use the ScrollTimeline Web Animations API for better performance, following the approach in #4090.Previously, the hook used
useScrollTop— a reactive scroll listener — to update thetopstyle of absolutely-positioned elements on every scroll event when the mobile Safari keyboard was open. This triggered React re-renders on every scroll.The new implementation drives the scroll tracking off the main thread via a CSS scroll-driven animation, eliminating those re-renders entirely.
Changes
src/@types/index.ts: AddScrollTimelineOptionsinterface andScrollTimelineclass global type declarations (same as perf(ScrollZone): rewrite parallax effect to use ScrollTimeline Web Animations API #4090)src/hooks/usePositionFixed.ts:supportsScrollTimelineconstant for feature detectionuseScrollTopdisabled when ScrollTimeline is supportedrefalongsideposition/top/bottom— callers attach it to their element to enable the animationuseEffect: setstoptoinitialTopin layout, then animatestranslateY(0)→translateY(maxScroll)scroll-driven;ResizeObserverondocument.bodyrecreates animation when content height changesscrollingElement.clientHeightfor accuratemaxScrollcalculationtopstyle for unsupported browserssrc/components/Toolbar.tsx,HamburgerMenu.tsx,ErrorMessage.tsx,TutorialScrollUpButton.tsx: Destructure returnedref, attach to target elementsrc/components/PopupBase.tsx: AddpositionFixedReftouseCombinedRefsalongside the forwarded ref and swipe-to-dismiss refTesting
yarn tsc --noEmitpassesyarn lintpasses