flowbite icon indicating copy to clipboard operation
flowbite copied to clipboard

Add optional chaining to `window` and `document` references

Open braebo opened this issue 2 years ago • 2 comments

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:

  1. Pick a modern framework with SSR
  2. Try to use flowbite
  3. You can't. window or document is not defined

Expected behavior It works

Desktop (please complete the following information): All

Smartphone (please complete the following information): All

braebo avatar Aug 30 '22 15:08 braebo

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!

zoltanszogyenyi avatar Sep 12 '22 12:09 zoltanszogyenyi

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.

braebo avatar Sep 14 '22 12:09 braebo

Hey @FractalHQ,

I'm considering this update for the v1.6.0 release. Did you manage to get some repo with an example?

zoltanszogyenyi avatar Dec 07 '22 14:12 zoltanszogyenyi

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.

zoltanszogyenyi avatar Jan 06 '23 20:01 zoltanszogyenyi

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.

braebo avatar Jan 06 '23 21:01 braebo

This has been fixed in the Flowbite v1.6.1 release.

zoltanszogyenyi avatar Jan 10 '23 17:01 zoltanszogyenyi