Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 13, 2025

  • Understand the feedback: Project uses Next.js static export, not SSR
  • Remove SSR-related test case from test suite
  • Update test descriptions to remove SSR context
  • Update hook comment to clarify this is for static build safety
  • Verify all tests pass (250 tests total, 4 for this hook)
  • Verify lint and format checks pass
  • Keep window guards in place (still needed for static export builds)
  • Fix prettier formatting (added trailing comma in test file)

💡 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.

Copilot AI changed the title [WIP] Fix 'window is not defined' error in useWindowResize hook Fix SSR "window is not defined" error in useWindowResize hook Dec 13, 2025
Copilot AI requested a review from frano-m December 13, 2025 06:21
@frano-m frano-m marked this pull request as ready for review January 5, 2026 02:58
Copy link
Contributor

@frano-m frano-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks CP.

@frano-m frano-m changed the title Fix SSR "window is not defined" error in useWindowResize hook feat: fix SSR "window is not defined" error in useWindowResize hook (#742) Jan 6, 2026
@frano-m frano-m changed the title feat: fix SSR "window is not defined" error in useWindowResize hook (#742) fix: fix sir "window is not defined" error in usewindowresize hook (#742) Jan 6, 2026
@frano-m frano-m changed the title fix: fix sir "window is not defined" error in usewindowresize hook (#742) fix: fix ssr "window is not defined" error in usewindowresize hook (#742) Jan 6, 2026
@frano-m frano-m changed the title fix: fix ssr "window is not defined" error in usewindowresize hook (#742) fix: fix "window is not defined" error in usewindowresize hook (#742) Jan 6, 2026
@frano-m
Copy link
Contributor

frano-m commented Jan 6, 2026

@copilot We do not support SSR in this project.
This is a Next.js static export (output: 'export') using the Pages Router with getStaticProps / getStaticPaths.

Please update this test suite to remove all SSR-related behavior and assumptions.

Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot We do not support SSR in this project.
This is a Next.js static export (output: 'export') using the Pages Router with getStaticProps / getStaticPaths.

...

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 AI requested a review from frano-m January 6, 2026 05:32
@frano-m
Copy link
Contributor

frano-m commented Jan 6, 2026

@copilot does the test still need the use of useFakeTimers?

Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot does the test still need the use of useFakeTimers?

Yes, useFakeTimers is still needed. The hook uses setTimeout for debouncing resize events (line 25), and two tests ("updates dimensions on window resize" and "debounces resize events with the specified timeout") use jest.advanceTimersByTime() to test the debouncing behavior. Without fake timers, these tests would need to wait for real timeouts, making them slower and potentially flaky.

Copy link
Contributor

Copilot AI left a 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 useEffect hook 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

Copy link
Contributor

@frano-m frano-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks CP!

@NoopDog NoopDog force-pushed the copilot/fix-window-is-not-defined-error branch from c50fb88 to f67f72c Compare January 6, 2026 08:39
@frano-m
Copy link
Contributor

frano-m commented Jan 6, 2026

@copilot fix prettier for the test

Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot fix prettier for the test

Fixed in commit 9639b29. Added trailing comma to match prettier formatting rules.

Copilot AI requested a review from frano-m January 6, 2026 08:54
Copy link
Contributor

@frano-m frano-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY CP!

@NoopDog NoopDog merged commit 44c42a2 into main Jan 6, 2026
2 checks passed
@frano-m frano-m deleted the copilot/fix-window-is-not-defined-error branch January 6, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants