fix: fix "window is not defined" error in usewindowresize hook (#742)#743
fix: fix "window is not defined" error in usewindowresize hook (#742)#743
Conversation
|
@copilot We do not support SSR in this project. Please update this test suite to remove all SSR-related behavior and assumptions. |
... Updated in commit c50fb88. Removed the SSR-related test case and updated comments to reflect that this is a Next.js static export project. The test suite now focuses on client-side behavior (window resize, debouncing, cleanup) without SSR assumptions. The window guards remain in place as they're still needed during static build when window is not available. |
|
@copilot does the test still need the use of useFakeTimers? |
Yes, |
There was a problem hiding this comment.
Pull request overview
This PR fixes a "window is not defined" error in the useWindowResize hook that occurs during Next.js static export builds. The fix adds window existence checks to prevent errors when the hook is called in environments where the window object is not available.
Key Changes:
- Added window guard in the
useEffecthook to skip event listener setup during static builds - Added window guard in
getWindowSize()function to return default dimensions (0,0) when window is unavailable - Added comprehensive test suite with 4 test cases covering basic functionality, resize events, debouncing, and cleanup
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/hooks/useWindowResize.ts | Added window existence checks in both the hook's useEffect and the getWindowSize helper function to prevent errors during static builds |
| tests/useWindowResize.test.ts | New test file with comprehensive test coverage for window resize functionality, including debouncing and event listener cleanup |
c50fb88 to
f67f72c
Compare
|
@copilot fix prettier for the test |
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.