Nuqs server-side is slow?
Unanswered
Black-tailed Gnatcatcher posted this in #help-forum
Black-tailed GnatcatcherOP
Unsure if I should post on nuqs or on here, as I'm unsure if my issue is with the understanding of the package or of next as a framework, but if there are any nuqs enthusiasts here:
When I use: https://nuqs.47ng.com/docs/server-side (the text above in the video), it seems slow and delayed to display a context, here is my code:
But when using a useQueryState (client side, which, I'd like to avoid to keep fetching server-side lower in my component tree), its much faster.
Am I doing something wrong?
When I use: https://nuqs.47ng.com/docs/server-side (the text above in the video), it seems slow and delayed to display a context, here is my code:
// searchParams.tsx
import {
createSearchParamsCache,
parseAsString,
} from 'nuqs/server';
export const searchParamsCache = createSearchParamsCache({
content: parseAsString.withDefault('overview').withOptions({ shallow: false }),
});
//page.tsx
const { content } = await searchParamsCache.parse(props.searchParams);
But when using a useQueryState (client side, which, I'd like to avoid to keep fetching server-side lower in my component tree), its much faster.
Am I doing something wrong?
1 Reply
Brown bear
Discussion opened (and answered) on the nuqs repo:
https://github.com/47ng/nuqs/discussions/968#discussioncomment-12764272
TL;DR: nuqs uses optimistic state updates client-side for a faster feedback, as the URL update (and therefore the roundtrip to the server for RSC rendering) is deferred in a throttled queue to avoid spamming servers with requests. But the largest contributor to that roundtrip feeling "slow" is the network latency.
https://github.com/47ng/nuqs/discussions/968#discussioncomment-12764272
TL;DR: nuqs uses optimistic state updates client-side for a faster feedback, as the URL update (and therefore the roundtrip to the server for RSC rendering) is deferred in a throttled queue to avoid spamming servers with requests. But the largest contributor to that roundtrip feeling "slow" is the network latency.