Next.js Discord

Discord Forum

Server component reload is not synchronized with client state?

Answered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
I'm building a small project to try and get a grip on how the app router and server components work and I'm facing a problem I cant seem to solve. I have a simple checkbox client component which pushes query params depending on what is selected then I have a server component that consumes these query params and fetches data based on them. The client component does router.replace/router.push onChange which normally triggers the server component to change but it so happens that they are usually out of sync. For example the checkboxes and query params would indicate state1 but the server fetching would indicate state 0 and so on.
I have tried messing with the caching revalidation, forcing the page to be dynamic and so on, stack overflow hasn't proven to useful either having already tried most of the solutions I could get my hands on without much success.

Is this usecase good for server components?
Is there any pattern im missing here?

here is the code: https://paste.ofcode.org/UNEyXSZf5iec9XxUNerL9F
Answered by Transvaal lion
the client components needs to be inside the server component that is fetching the information think that was the problem
View full answer

16 Replies

Transvaal lionOP
I've consulted this https://nextjs-faq.com/sharing-client-side-state-with-server-components and it seems like what im doing is pretty similar
Could the problem be the lack of the useTransition?
Transvaal lionOP
the client components needs to be inside the server component that is fetching the information think that was the problem
Answer
yeah you arent “just changing state” either
Transvaal lionOP
they were both on the same level
you are full ass fetching on change
you should ABSOLUTELY be using useTransition when fetching
Transvaal lionOP
good to know will that keep that in mind from now on
did you spot anything else that was off?
Transvaal lionOP
I'm a backend developer plan to move off of it soon once i get a bit more into styling
i saw it as “oh it does all the things this is nice”. then i learned how it all worked and eventually saw the error of my ways
Transvaal lionOP
Yeah, I already see the error in my ways just don't have the tools to dig me out of it yet but will get there
appreciate the help