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

window is not defined (ssr) #1291

Closed
dackmin opened this issue Jul 11, 2024 · 9 comments
Closed

window is not defined (ssr) #1291

dackmin opened this issue Jul 11, 2024 · 9 comments
Labels

Comments

@dackmin
Copy link

dackmin commented Jul 11, 2024

Describe the bug
v5 is using window inside @iframe-resizer/child which breaks server-side rendering.

To Reproduce
Load a child from something like Next (that has server side rendering)

Expected behavior
v4 doesn't and works perfectly.

Screenshots
Capture d’écran 2024-07-11 à 08 48 45

Desktop

  • OS: MacOS Sonoma v14.5.0
  • Browser: Chrome v126.0.6478.127 (arm64)
  • Node: v20.13.1
  • Next: v14.2.4
  • @iframe-resizer/child: latest (5.1.5 right now)
@davidjbradshaw
Copy link
Owner

Thanks for this, the child code checks for window and halts if it is not there. However, their where a couple of variables getting setup before that point that had references to window in them, that I now also guard. This was not an issue in v4 due to the build process being different and allowing me to check for window and exit before defining anything. But sadly that is not possible with Rollup.

I will hopefully get a beta out with a number of things in it later today.

@davidjbradshaw
Copy link
Owner

Could you please try version 5.2.0-beta.3 and let me know if that fixes this for you?

@dackmin
Copy link
Author

dackmin commented Jul 11, 2024

Capture d’écran 2024-07-11 à 13 38 31

almost there 😄

@dackmin
Copy link
Author

dackmin commented Jul 11, 2024

here's a codesandbox to see the bug in action: https://codesandbox.io/p/devbox/iframe-resizer-ssr-issue-dr8r95

@davidjbradshaw
Copy link
Owner

OK different and more robust approach. I've wrap the whole thing in a function, that only gets called if window is available.

5.2.0-beta.4

Hopefully it works for you this time.

@davidjbradshaw
Copy link
Owner

Make that 5.2.0-beta.5.

I need to come up with an SSR test, as everything is currently configures for Client Side and auto mocks window and document.

@dackmin
Copy link
Author

dackmin commented Jul 16, 2024

Works perfectly inside codesandbox, I can't work on the original project right now but that's the exact same configuration so it should work too.
Well done!

@davidjbradshaw
Copy link
Owner

Thanks for letting me know. Just putting the finishing touches to rewriting the performance observer code and then will push out the final release of 5.2.

@davidjbradshaw
Copy link
Owner

Released in v5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants