davidjbradshaw / iframe-resizer

Keep iFrames sized to their content.
https://iframe-resizer.com
Other
6.65k stars 981 forks source link

window is not defined (ssr) #1291

Closed dackmin closed 1 month ago

dackmin commented 1 month ago

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

davidjbradshaw commented 1 month ago

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 commented 1 month ago

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

dackmin commented 1 month ago
Capture d’écran 2024-07-11 à 13 38 31

almost there 😄

dackmin commented 1 month ago

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

davidjbradshaw commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

Released in v5.2