Closed tkovs closed 1 year ago
I solved it by using both strategies 🤦
import { lazy, Suspense } from "preact/compat";
import { IS_BROWSER } from "$fresh/runtime.ts";
const Flicking = lazy(() =>
import("https://esm.sh/@egjs/preact-flicking@4.11.0")
);
export const Carousel = () => {
if (!IS_BROWSER) {
return <p>Not browser</p>;
}
return (
<Suspense fallback={<p>Loading...</p>}>
<Flicking />
</Suspense>
)
);
The solution of #1809 didn't help me because I need the imported component.
I started a Fresh website, and I need a carousel component. For that, I chose the flicking lib. I'm trying to render a Flicking component, but the
run
breaks:The current code:
Previous tries
I tried to check for
typeof window !== 'undefined'
before rendering theFlicking
component, but it didn't work.I also tried to use lazy imports:
But the initial result is a
[object Promise]
on the screen, and when I restart the page, theReferenceError: document is not defined
comeback. (ps.: this way, the build process doesn't break - the error appears on the page)