From 07597d7cfcf23e87cefcaed27318ba3504ef3d50 Mon Sep 17 00:00:00 2001 From: "D. Elmo Peele" Date: Thu, 26 Sep 2024 06:24:12 -0400 Subject: [PATCH 1/2] Protect the use of document to resolve SSR issues. 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 --- js/lib/dom.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/lib/dom.js b/js/lib/dom.js index 1b0a252..6738ad1 100644 --- a/js/lib/dom.js +++ b/js/lib/dom.js @@ -1,6 +1,7 @@ -const range = document.createRange(); +var range = null; export function parseHTML(html) { + if (range == null) { range = document.createRange() } return range.createContextualFragment(html); } From edcaa7898c6624a0a2cab9523f8de084ed4dcfe7 Mon Sep 17 00:00:00 2001 From: depeele Date: Fri, 27 Sep 2024 12:58:22 -0400 Subject: [PATCH 2/2] Update js/lib/dom.js Accept the suggested change from `var` to `let` Co-authored-by: 20x-dz <113644268+20x-dz@users.noreply.github.com> --- js/lib/dom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/lib/dom.js b/js/lib/dom.js index 6738ad1..00051e0 100644 --- a/js/lib/dom.js +++ b/js/lib/dom.js @@ -1,4 +1,4 @@ -var range = null; +let range = null; export function parseHTML(html) { if (range == null) { range = document.createRange() }