-
Notifications
You must be signed in to change notification settings - Fork 0
fix: fix "window is not defined" error in usewindowresize hook (#742) #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
frano-m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks CP.
|
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
frano-m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks CP!
c50fb88 to
f67f72c
Compare
|
@copilot fix prettier for the test |
frano-m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TY CP!
💡 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.