Skip to content

perf(usePositionFixed): rewrite to use ScrollTimeline Web Animations API#4091

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/rewrite-usepositionfixed-scroll-timeline
Closed

perf(usePositionFixed): rewrite to use ScrollTimeline Web Animations API#4091
Copilot wants to merge 2 commits intomainfrom
copilot/rewrite-usepositionfixed-scroll-timeline

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

Summary

Rewrites usePositionFixed.ts to 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 the top style 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: Add ScrollTimelineOptions interface and ScrollTimeline class global type declarations (same as perf(ScrollZone): rewrite parallax effect to use ScrollTimeline Web Animations API #4090)
  • src/hooks/usePositionFixed.ts:
    • Module-level supportsScrollTimeline constant for feature detection
    • useScrollTop disabled when ScrollTimeline is supported
    • Returns a ref alongside position/top/bottom — callers attach it to their element to enable the animation
    • ScrollTimeline useEffect: sets top to initialTop in layout, then animates translateY(0)translateY(maxScroll) scroll-driven; ResizeObserver on document.body recreates animation when content height changes
    • Uses scrollingElement.clientHeight for accurate maxScroll calculation
    • Fallback to JS-driven top style for unsupported browsers
  • src/components/Toolbar.tsx, HamburgerMenu.tsx, ErrorMessage.tsx, TutorialScrollUpButton.tsx: Destructure returned ref, attach to target element
  • src/components/PopupBase.tsx: Add positionFixedRef to useCombinedRefs alongside the forwarded ref and swipe-to-dismiss ref

Testing

  • ✅ TypeScript: yarn tsc --noEmit passes
  • ✅ Lint: yarn lint passes
  • ✅ Unit tests: 1325/1325 passed

Copilot AI and others added 2 commits April 11, 2026 01:14
…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>
@raineorshine
Copy link
Copy Markdown
Contributor

Still jittery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants