-
Notifications
You must be signed in to change notification settings - Fork 26.3k
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
ReferenceError: window is not defined... in client component? #66066
Comments
Client components still run on the server. https://nextjs.org/docs/app/building-your-application/rendering/client-components
The term "client component" means that it also runs on the client, not that it just runs on the client exclusively. Please read the documentation before opening issues like this to make maintainer's life a bit easier 😄 |
As the above comment says, client components are still SSR'd, they are just the components you have used up till now, the new thing are server components, which only render server side, and never share their JS with the client. I can understand the confusion, as the name itself has some weight to it, but also, tech-influencers have spread this misinterpretation. |
Hi, The thing is that, your component render pass should be pure, that's like the main React "rule". Reading from the window object like that, is not pure, the width might change between renders, so to speak. So what you can do is:
Also, reading from the |
This is a bug/issue report area, people here focus on narrowing down reports into a reproducible demo, or a non-issue result. For other matters, we should use the discussions tab. |
Thanks bro and sorry for opening an issue and bothering you all because of my carelessness. |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/mirasayon/reproduction-app
To Reproduce
Current vs. Expected behavior
Current: There is a strange error and does not allow to build the application
There should be no error since it is a client component
Provide environment information
Which area(s) are affected? (Select all that apply)
Runtime, Testing
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered: