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

Fix ReferenceError: window is undefined Server-Side-Rendering #3446

Merged
merged 1 commit into from Mar 31, 2021
Merged

Fix ReferenceError: window is undefined Server-Side-Rendering #3446

merged 1 commit into from Mar 31, 2021

Conversation

tillhainbach
Copy link

@tillhainbach tillhainbach commented Mar 31, 2021

fix #3444 by wrapping with typeof window !== 'undefined'

Issues was introduced by v5.2.2

Edit:
Patch for 15b0796

Changed target branch to legacy-v5 (I hope that's the correct one..)

@tillhainbach tillhainbach changed the base branch from master to legacy-v5 March 31, 2021 07:54
@RomanHotsiy
Copy link

Pinging @probablyup directly, just in case he may be unsubscribed from other notifications in this repo.

@probablyup, sorry for bothering 🙇.
It looks like a straightforward and safe fix and there are many people impacted so decided to ping you. Thanks for your hard work on this project!

@quantizor quantizor merged commit 06afb1b into styled-components:legacy-v5 Mar 31, 2021
@quantizor
Copy link
Contributor

This is released in 5.2.3

@davidnegley
Copy link

is the same fix also needed here https://github.com/styled-components/styled-components/blob/legacy-v5/packages/styled-components/src/base.js#L41 to fix #3374 ?

@tillhainbach tillhainbach deleted the fix-ssr branch April 28, 2021 22:43
@tillhainbach
Copy link
Author

is the same fix also needed here https://github.com/styled-components/styled-components/blob/legacy-v5/packages/styled-components/src/base.js#L41 to fix #3374 ?

I don't thing so. That if guards against a __SERVER__ flag. Looks like the __SERVER__ global is no set correctly

@nuwan-dammika
Copy link

Hi @tillhainbach

I have inherited a project that build same react code base and used to do SSR and client side rendering .

It uses Parcel build which use styled-components.browser.esm.js (for final js build) because it is building for browser. And on SSR following line error out

https://github.com/styled-components/styled-components/blob/legacy-v5/packages/styled-components/src/base.js#L41
with
window is not defined

I tried Parcel build with --target node , which fixes above issue (linked) but brings whole other errors (not related to styled-components). So have to make this work.

Currently fixed to 5.1.1, because that's the last version with window is safely handled. So do you have any suggestion to inject __SEVER__ though react code or that line get fixed.

Thanks

@nuwan-dammika
Copy link

is the same fix also needed here https://github.com/styled-components/styled-components/blob/legacy-v5/packages/styled-components/src/base.js#L41 to fix #3374 ?

I have the same issue, in my case same code base is used for SSR and Client Rendering .

@samimakicc samimakicc mentioned this pull request Jun 14, 2022
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.

ReferenceError: window is not defined - NextJs 10.1.2
8 participants