perf: Optimize GradientBlinds pointer move handler

- Removed synchronous `getBoundingClientRect` call from `pointermove` handler
- Implemented caching of canvas dimensions and scroll position using `ResizeObserver`
- Added logic to compensate for scroll delta in pointer position calculation
- Added regression test to verify `getBoundingClientRect` is not called during pointer interaction
- Fixed `ogl` mock in tests to include `Geometry`
This commit is contained in:
google-labs-jules[bot]
2026-01-24 10:02:30 +00:00
parent 77fd62447c
commit 5d29f05248
2 changed files with 53 additions and 3 deletions

View File

@@ -22,6 +22,9 @@ vi.mock('ogl', () => {
Mesh: class {
remove() {}
},
Geometry: class {
remove() {}
},
Triangle: class {
remove() {}
},
@@ -129,4 +132,33 @@ describe('GradientBlinds', () => {
unmount();
expect(disconnectSpy).toHaveBeenCalled();
});
it('minimizes getBoundingClientRect calls during pointer move', () => {
const { unmount } = render(<GradientBlinds />);
// Spy on getBoundingClientRect
// Note: In jsdom, canvas is an HTMLCanvasElement which inherits from HTMLElement
const spy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect');
// Trigger pointer move to clear any initial calls or verify baseline
// The initial render calls resize(), which calls getBoundingClientRect on container
// Clear spy history from initial render
spy.mockClear();
act(() => {
const event = new PointerEvent('pointermove', {
clientX: 200,
clientY: 200,
bubbles: true,
});
window.dispatchEvent(event);
});
// EXPECTATION: It should NOT be called.
// This will fail currently.
expect(spy).not.toHaveBeenCalled();
unmount();
});
});