-
Hi! I'm using Next.js with the App Router, and I’ve been wondering how Here’s my questionHow exactly does My setup// page.tsx
import ClientComponent from './_component/ClientComponent';
export const Page = () => {
return <ClientComponent />;
};
// ClientComponent.tsx
'use client';
import { useSuspenseQuery } from '@tanstack/react-query';
import { randomOptions } from '@/shared/data/getTodoItem/queries';
export default function ClientComponent() {
console.log('@@@ in client component before query');
const { data: randomData } = useSuspenseQuery(randomOptions());
console.log('@@@ in client component after query', randomData);
return (
<>
<h2>Client Component</h2>
<p>randomData id: {randomData.id}</p>
<p>randomData todo: {randomData.todo}</p>
</>
);
} In this case, I expected that the ![]() This made it appear as if To be more specific, when observing the behavior visually, the HTML returned from the server includes empty data, but the content shown on the screen contains the randomData that was fetched on the server. After that, the client triggers the API call again, and since the returned data differs, a hydration mismatch occurs. Does |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This problem still occurs even when the import { Suspense } from 'react';
import ClientComponent from './_component/ClientComponent';
export const Page = () => {
return (
<Suspense fallback={<div>Loading...</div>}>
<ClientComponent />
</Suspense>
);
};
export default Page; |
Beta Was this translation helpful? Give feedback.
-
yes, because client components also render on the server during SSR, and Everything you said is expected. Please read the docs on SSR, especially the advanced ssr guide around streaming. You have to get data into the client cache somehow, and we offer multiple ways to do so. |
Beta Was this translation helpful? Give feedback.
yes, because client components also render on the server during SSR, and
useSuspenseQuery
throws a promise during render that nextJs picks up on.Everything you said is expected. Please read the docs on SSR, especially the advanced ssr guide around streaming. You have to get data into the client cache somehow, and we offer multiple ways to do so.