Skip to content
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

Protect the use of document to resolve SSR issues. #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

depeele
Copy link

@depeele depeele commented Sep 26, 2024

To enable inclusion in applications that may also use SSR, the invocation of document.createRange() needs to be moved out of the global scope. Moving it into the parseHTML() method resolves this issue since it will only be executed if the component is actually used (on the browser side).

Full inclusion of this component by flowbite 2.4.0 introduced SSR-related bugs across multiple frameworks (Nuxt, NextJS, Sveltekit) due to this unprotected use of document.

Prior to flowbite 2.4.0, flowbite-datepicker was included via a "plugin" approach that mitigated this unprotected use of document,

This resolves issue #41

To enable inclusion in applications that *may also use* SSR, the
invocation of `document.createRange()` needs to be moved out of the
global scope. Moving it into the `parseHTML()` method resolves this
issue since it will only be executed if the component is actually used
(on the browser side).

Full inclusion of this component by flowbite 2.4.0 introduced
SSR-related bugs across multiple frameworks (Nuxt, NextJS, Sveltekit)
due to this unprotected use of `document`.

Prior to flowbite 2.4.0, flowbite-datepicker was included via a "plugin"
approach that mitigated this unprotected use of `document`,

This resolves issue themesberg#41
js/lib/dom.js Outdated Show resolved Hide resolved
Accept the suggested change from `var` to `let`

Co-authored-by: 20x-dz <[email protected]>
@tristan-zander
Copy link

I am having this same issue as well when trying to import flowbite into a Deno Fresh project using SSR. I applied the fix to the file and it did resolve my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants