Closed depeele closed 2 months ago
I've also added a comment to a related flowbite-datepicker
issue #41 recommending the typeof document
solution.
Hey @depeele,
For SSR you just need to make sure the client (aka. browser) is available.
Here's a guide for Angular's SSR, for example:
https://flowbite.com/docs/getting-started/angular/#using-with-angular-ssr
Can you please try this? Technically you can use the datepicker plugin directly from the core JS Flowbite.
I'm running into this issue when trying to deploy a project with Astro. We're not even using a datepicker anywhere and it's causing the build error
@zoltanszogyenyi : This approach does NOT resolve the issue I have reported. I believe this issue should be reopened because my problem has not been resolved. Below are the details of the ongoing problem:
@zoltanszogyenyi suggested:
For SSR you just need to make sure the client (aka. browser) is available.
Here's a guide for Angular's SSR, for example:
https://flowbite.com/docs/getting-started/angular/#using-with-angular-ssr
Can you please try this? Technically you can use the datepicker plugin directly from the core JS Flowbite.
For my use-case:
const range = document.createRange();
Item 3 is the root cause of the issue which was effectively mitigated by the "plugin" approach previously used by flowbite, specifically for this date picker component.
To enable the use of newer versions of flowbite in projects such as mine, the webpack configuration and src/plugins/
need to be reverted to what was used for flowbite v2.3.0.
Again, given that this issue is related to a single unprotected use of document
within a sub-module that flowbite has chosen to include, requiring the end-user to ensure flowbite is not included in SSR code seems like over-kill — particularly in cases where this approach is not an option.
Every thing else in flowbite works fine within SSR code. This single date picker problem is the cause of this issue.
Thank you!
This entire issue seems related to pull request 907
Describe the bug The removal of the datepicker-related webpack configuration and src/plugins/ between flowbite v2.3.0 and v2.4.0 introduced an error with SSR rendered code.
This removal causes the full flowbite-datepicker package to be included in the final, minimized version of flowbite. Within the full flowbite-datepicker package, the first line of js/lib/dom.js causes SSR code to fail with a "document is not defined" error:
For SSR to be able to properly use flowbite.min.js either:
src/plugins/
need to be reverted to what was used for flowbite v2.3.0;Issue #921 has a comment suggesting the use of a composable to ensure flowbite is not included in SSR code, but there are cases where the way flowbite is included is not in the control of the end user (e.g. svelte-flowbite).
Given that this issue is related to a single unprotected use of
document
, requiring the end-user to ensure flowbite is not included in SSR code seems like over-kill.