-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[BUG] - div-in-p
issue in tooltip
#3975
Comments
@wingkwong Could you please assign this issue to me? |
@rishabhverma54321 assigned |
@rishabhverma54321 thanks! I can review and test your RR if you want |
Hi @erfanium thanks for asking! I'm not able to replicate this issue on my end. After debugging, I found that if you pass a valid JSX element into the Tooltip (which, in this case, you did), the isValidElement condition will always evaluate to true on both server-side and client-side hydration, resulting in the same element rendering on both sides. Could you provide a sandbox URL or screenshot to help troubleshoot? |
@rishabhverma54321 Here is the correct one: import { Tooltip } from "@nextui-org/react";
import { connection } from "next/server";
async function AsyncWrapper({ children }: { children: React.ReactNode }) {
return <>{children}</>;
}
export default function Home() {
connection();
return (
<Tooltip content="Hello world">
<AsyncWrapper>
<div>Card</div>
</AsyncWrapper>
</Tooltip>
);
} You just need to wrap the Tooltip content inside a async server-side component. and here is the reproduction repo: |
@erfanium I found that on the server side, AsyncWrapper might return a representation that resembles a lazy-loaded promise (i.e., it returns an object with a _payload indicating it's fulfilled). This could be why isValidElement doesn't recognize it correctly. One approach to address this is to wrap server-rendered content in a Suspense boundary to ensure proper client-side rendering. import { Tooltip } from "@nextui-org/react";
import { connection } from "next/server";
async function AsyncWrapper({ children }: { children: React.ReactNode }) {
return <>{children}</>;
}
export default function Home() {
connection();
return (
<Tooltip content="Hello world">
<Suspense fallback={<div>Loading...</div>}>
<AsyncWrapper>
<div>Card</div>
</AsyncWrapper>
</Suspense>
</Tooltip>
);
} |
@rishabhverma54321 I think something is wrong here. NextUI should either support Lazy object as the children or actually fix the validation logic to throw a meaningful error message. Because the current logic (wrap the Lazy object with a p tag) is not correct at all. |
NextUI Version
2.4.8
Describe the bug
When using server components, there is a
div-in-p
hydration issue.I have debugged that.
nextui/packages/components/tooltip/src/tooltip.tsx
Lines 42 to 50 in 8de427b
the result of this
isValidElement(children)
condition isfalse
on server-side, but it will betrue
on client hydration. which results in different html output and a hydration error.Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
use this page.tsx (updated)
Expected behavior
no error
Screenshots or Videos
No response
Operating System Version
Linux
Browser
Chrome
The text was updated successfully, but these errors were encountered: