Next.js Discord

Discord Forum

Server component passed as children to client modal component fetches its data before modal is shown

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
We've ran into an unexpected issue, where the server component we pass as children to the client modal component is fetching it's data before the modal is ever shown.

Is there any way to prevent this from happening, so the server component waits with fetching its data until the client component modal is opened?

3 Replies

Sun bear
I think in this case you need to fetch the data client side. Then you can fetch it when the modal is open.

Then the modal will open and it will take a little loading time and then you can see the data. You could add a loading state while its loading
Transvaal lionOP
So if you pass a server component as a child to a client component that is not mounted yet, the server component does not wait for the client component to mount, until it (the server component) fetches its daga? It fetches its data at the time it is passed as a property?
Sun bear
I would say yes but maybe someone else could confirm or explain how its handled