flowbite
flowbite copied to clipboard
Add optional chaining to `window` and `document` references
Describe the bug Flowbite breaks on the server. It should not assume it's always on the client.
To Reproduce Steps to reproduce the behavior:
- Pick a modern framework with SSR
- Try to use flowbite
- You can't.
window
ordocument
is not defined
Expected behavior It works
Desktop (please complete the following information): All
Smartphone (please complete the following information): All
Hey @FractalHQ,
Thanks for bringing this up.
Do you have any specific solution in mind?
I'm not sure I can reproduce this since I haven't yet tried a framework with SSR.
Thanks!
Usually this is as simple as optional chaining any calls to window or document, or checking if typeof window != undefined. It would be ideal if flowbite could be rendered to a page without relying on client side browser apis because some websites opt out of client side hydration altogether when using ssr (or alternatively, when pre-rendering pages at build-time).
If it helps, I can make a simple repro repo or stackblitz.
Hey @FractalHQ,
I'm considering this update for the v1.6.0
release. Did you manage to get some repo with an example?
Hey @FractalHQ,
Sorry for the long wait. This commit fixes SSR integration: https://github.com/themesberg/flowbite/commit/d4d09b9dcc6456f8a13553a696536f87b0bc3e22
Will be released for v1.6.1
. Used this and it's confirmed working with Nuxt.js v3 with SSR.
Awesome! I started a repro and was having trouble recreating the issue and forgot to follow up here -- sorry about that! Glad it's all sorted now.
This has been fixed in the Flowbite v1.6.1 release.