Skip to content

Fix landing page animation resource leak on navigation - #74

Open
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
jules/fix-landing-animation-leak-js0-f98b6031-49c4-4ce3-b4a8-9e0ce34c122e
Open

Fix landing page animation resource leak on navigation#74
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
jules/fix-landing-animation-leak-js0-f98b6031-49c4-4ce3-b4a8-9e0ce34c122e

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

Summary

This PR resolves a critical performance and resource leak where the landing page canvas background animation continues to run indefinitely in the background after a user navigates to another route (such as CV, publications, or projects).

Why This Is Necessary (Rationale)

The interactive landing page animation relies on a recursive requestAnimationFrame loop that starts after a initial 400ms delay. Previously, the cleanup function returned by Svelte's onMount in src/routes/+page.svelte only disconnected the layout ResizeObserver.

Because it failed to clear the scheduled setTimeout and active requestAnimationFrame processes, the animation cycles continued to run invisibly on subpages. This caused substantial, unnecessary CPU/GPU load, resulting in quick battery drain and thermal throttling—especially on mobile devices.

By tracking and explicitly canceling both the pending timeout and the active frame rendering, we eliminate these background tasks completely, restoring baseline resource utilization when browsing subpages.

Key Decisions & Changes

  • Lifecycle Tracking: Introduced variables to track the pending startup timeout ID and the active animation frame ID (requestAnimationFrame).
  • Complete Teardown: Enhanced the onMount cleanup return function to:
    • Cancel any pending delayed starts using clearTimeout if the user leaves before 400ms.
    • Stop active rendering loops using cancelAnimationFrame.
    • Maintain existing layout observer teardown integrity (ResizeObserver.disconnect()).
  • Constraint Respect: Resolved the issue without implementing visibility-aware window focus listeners, keeping layout monitoring fully functional when navigating back and resizing the viewport.

Verification & Acceptance Criteria

  • Instant Halt: Animation loop halts execution immediately when navigating away from the home page.
  • Early Cancelation: Leaving the page within the first 400ms successfully aborts the scheduled animation start.
  • No Duplicate Loops: Navigating back and forth between routes does not spin up duplicated or orphan drawing cycles.
  • Responsive Layouts: Resizing the viewport still triggers the layout observer correctly after navigating back to the home page.

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.

0 participants