-
Notifications
You must be signed in to change notification settings - Fork 765
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
datepicker causing error in SSR starting with version v2.4.0 (document is not defined) #950
Comments
I've also added a comment to a related |
Pin flowbite to v2.3.0 (actually, <2.4.0). flowbite 2.4.0 changed the way it imported flowbite-datepicker: - removed `src/plugins` and the related webpack configuration that restricted what was actually included from flowbite-datepicker in the final flowbite.min.js; - now includes the entire flowbite-datepicker package in the final flowbite.min.js; flowbite-datepicker has (always had) an issue that causes an SSR "document is not defined" error due to [lib/js/jdom.js](https://github.com/themesberg/flowbite-datepicker/blob/a343785aa01c7671f891cacc491040e238c4acc5/js/lib/dom.js#L1): ```javascript var range = document.createRange(); ``` This issue can be easily resolved within flowbite-datepicker by changing the line to: ```javascript var range = (typeof document !== 'undefined' && document.createRange()); ``` Reported: - flowbite: [issue 950](themesberg/flowbite#950); - flowbite-datepicker: added a [comment](themesberg/flowbite-datepicker#41 (comment)) to an existing, related issue;
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 my use-case:
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 Again, given that this issue is related to a single unprotected use of 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 |
This is a contradiction. The client cannot be made available on the server. If what you meant is to "ensure to not load this on the server by checking if it's running on the client", the this is exactly the issue that people are reporting (e.g. themesberg/flowbite-datepicker#41 or here), as the datepicker code failing is still parsed on the server. There have been posted a couple of decent solutions, please pick one and apply it. Thank you very much in advance! |
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.The text was updated successfully, but these errors were encountered: