Refactor FancyCursor to use mouseover delegation

- Moves expensive DOM checks (`closest`) and class toggling from `mousemove` loop to `mouseover` handler.
- Removes `document.elementFromPoint` fallback to eliminate layout thrashing.
- Updates tests to verify performance improvements.
- Fixes `Hero.test.tsx` missing jsdom environment.
This commit is contained in:
google-labs-jules[bot]
2026-01-23 09:27:45 +00:00
parent acfbb8571c
commit d5b079d452
3 changed files with 21 additions and 29 deletions

View File

@@ -86,26 +86,22 @@ describe('FancyCursor', () => {
document.body.removeChild(link);
});
it('uses fallback elementFromPoint if hoveredElement is null', () => {
it('does not call elementFromPoint on mousemove', () => {
// Reset elementFromPoint mock
const mockElementFromPoint = vi.fn();
// @ts-ignore
document.elementFromPoint = mockElementFromPoint;
// We need to remount to reset internal state if any.
// However, 'hoveredElement' variable was defined INSIDE the component in my edit.
// Let's double check that.
render(<FancyCursor />);
// Trigger mousemove WITHOUT prior mouseover.
// This should trigger the fallback.
// Trigger mousemove
fireEvent.mouseMove(window, { clientX: 10, clientY: 10 });
act(() => {
vi.runAllTimers();
});
expect(mockElementFromPoint).toHaveBeenCalledWith(10, 10);
// Should NOT be called in the optimized version
expect(mockElementFromPoint).not.toHaveBeenCalled();
});
});