Open gamliela opened 4 months ago
Same, see it on a Remix project that I tried to include Flowbite into today. In my case, I initialize flowbite via
import 'flowbite';
. Removing that line fixes the error though that's needed for Flowbite's JS to work. I've also tried including the CDN JS script, it causes the same error listed by the OP.
@vasanth-asokan I was thinking of trying Remix too - good to know it's having the same problem. Do you get the exact same error message? I thought this error is Next.js specific.
Exact same error in the trailing parts of the stack trace, of course the earlier parts vary... I came here trying to see if anyone's run into it before and was surprised to see the error report just a day earlier from you :)
Okay I see that's a React error, caused by the static import 'flowbite'
itself. The module is messing up with the DOM when it's first loaded. I think that's a Flowbite bug, as DOM changes should happen only during explict initFlowbite() call.
Anyway my workaround was to import Flowbite with a dynamic import, and initalise it in useEffect
. So a component to init flowbite could look like:
"use client";
import { useEffect } from "react";
// import { initFlowbite } from "flowbite"; <-- don't do that!
export function InitFlowbite() {
useEffect(() => {
import("flowbite").then((module) => module.initFlowbite());
}, []);
return null;
}
Describe the bug
initFlowbite
must be called after the DOM has been rendered. When using React Server Components and Next.js, a reasonable implementation is to callinitFlowbite
within a client component in auseEffect
block. This works fine, but the following warning is emitted to the console:Warning: Extra attributes from the server: style
+ stacktrace in red color.Note - I'm not using flowbite-react, as it works significantly different from pure javascript flowbite and I can't copy&paste html from the website (I'm a paid user and I'm relying on the code snippets from the website). This difference is a different issue though.
To Reproduce
import { useEffect } from "react"; import { initFlowbite } from "flowbite";
export function InitFlowbite() { useEffect(() => { initFlowbite(); }, []);
return null; }