Skip to content

Add RAF cleanup to Manuals.tsx scroll listener#19

Draft
Copilot wants to merge 2 commits intoperf/optimize-manuals-scroll-10061944444742086940from
copilot/sub-pr-16
Draft

Add RAF cleanup to Manuals.tsx scroll listener#19
Copilot wants to merge 2 commits intoperf/optimize-manuals-scroll-10061944444742086940from
copilot/sub-pr-16

Conversation

Copy link
Contributor

Copilot AI commented Feb 4, 2026

The scroll optimization introduced RAF throttling but didn't cancel pending callbacks on unmount, allowing state updates and DOM access on detached elements.

Changes:

  • Track RAF ID in local variable within useEffect scope
  • Cancel pending RAF callback in cleanup function
  • Clear RAF ID after execution to maintain idempotency

Pattern:

useEffect(() => {
  let rafId: number | null = null;
  
  const handleScroll = () => {
    if (!ticking.current) {
      rafId = window.requestAnimationFrame(update);
      ticking.current = true;
    }
  };
  
  return () => {
    removeEventListener('scroll', handleScroll);
    if (rafId !== null) cancelAnimationFrame(rafId);
  };
}, []);

Follows established pattern from AudioVisualizer.tsx, PulseVisualizer.tsx, and PlanetaryView.tsx.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link

vercel bot commented Feb 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
thisisdefrag Error Error Feb 4, 2026 11:31pm
v0-thisisdefrag Error Error Feb 4, 2026 11:31pm

Co-authored-by: cjo93 <186514116+cjo93@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize Manuals.tsx scroll listener Add RAF cleanup to Manuals.tsx scroll listener Feb 4, 2026
Copilot AI requested a review from cjo93 February 4, 2026 23:24
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