perf: pause GradientBlinds animation when off-screen

Removes the unconditional start of the animation loop on mount. The loop is now exclusively managed by the existing IntersectionObserver, ensuring it only runs when the component is visible.

Updates tests to reflect this behavior by simulating intersection events to trigger the animation.
This commit is contained in:
google-labs-jules[bot]
2026-01-23 09:29:42 +00:00
parent acfbb8571c
commit fe6e07fe92
2 changed files with 19 additions and 4 deletions

View File

@@ -66,8 +66,17 @@ describe('GradientBlinds', () => {
vi.clearAllMocks();
});
it('starts animation loop on mount', () => {
it('does not start animation loop on mount until visible', () => {
const { unmount } = render(<GradientBlinds />);
expect(rafSpy).not.toHaveBeenCalled();
// Simulate on-screen
act(() => {
if (ioCallback) {
ioCallback([{ isIntersecting: true } as IntersectionObserverEntry]);
}
});
expect(rafSpy).toHaveBeenCalled();
unmount();
expect(cancelRafSpy).toHaveBeenCalled();
@@ -76,7 +85,15 @@ describe('GradientBlinds', () => {
it('pauses animation loop when off-screen and resumes when on-screen', () => {
const { unmount } = render(<GradientBlinds />);
// Initial start
// Should not start initially
expect(rafSpy).not.toHaveBeenCalled();
// Simulate on-screen (start)
act(() => {
if (ioCallback) {
ioCallback([{ isIntersecting: true } as IntersectionObserverEntry]);
}
});
expect(rafSpy).toHaveBeenCalledTimes(1);
// Reset spies to check for subsequent calls