Skip to content
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

useWarningLogger only runs on the client #2251

Merged
merged 4 commits into from
Sep 19, 2024

Conversation

r100-stack
Copy link
Member

@r100-stack r100-stack commented Sep 18, 2024

Changes

An example from examples was failing on the Astro docs site:

image

This is because useWarningLogger uses window (not available on the server), but in Astro, that component was running on the server.

timeoutRef.current = window.setTimeout(() => {

So, this PR uses getWindow() instead of window. getWindow() returns undefined when window does not exist instead of giving an error.

/**
* Get window if it is defined.
* Used to support SSR/SSG applications.
*/
export const getWindow = () => {
return typeof window === 'undefined' ? undefined : window;
};

Testing

  • Confirmed that the warnings (e.g. IconButton is missing the ``label`` prop. warning) are still working.
  • Confirmed that the new example I was adding that was giving the error on the docs site is now working.

Docs

No changeset needed imo as not a significant change for the user.

@r100-stack r100-stack marked this pull request as ready for review September 18, 2024 19:41
@r100-stack r100-stack requested a review from a team as a code owner September 18, 2024 19:41
@r100-stack r100-stack requested review from mayank99 and smmr-dn and removed request for a team September 18, 2024 19:41
@r100-stack r100-stack enabled auto-merge (squash) September 19, 2024 15:15
@r100-stack r100-stack merged commit ba9bc9a into main Sep 19, 2024
16 of 17 checks passed
@r100-stack r100-stack deleted the r/use-warning-logger-window-error branch September 19, 2024 15:23
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