Am I using nuqs with nextjs wrong? #778
-
Nuqs version: 2.2.2 Don't get me wrong, I really really like nuqs and see the use of it! It's super awesome! But I just implemented it a big project. Replacing the previous code using nextjs suggestion on using native history API to avoid unnecessary re-renders of RSC. Nuqs turned the code to be much cleaner and easier to work with. However now we started to get a lot of server re-render which is not what I was expecting because of this in the docs. I'm now considering removing it to go back to the previous implementation we had. But I don't want to do that, so before I do it what am I missing here? How is it working under the hood? Does it use the NextJs suggested way of working with the native history API as stated in docs with shallow? Enlighten a stupid person as me please 😅 As an example, I have a simple dropdown with items that you can select, underneath is a list things based on the items Id. Code with the list to show, cleaned to show only the Id atm:
The select:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 15 replies
-
Are you sure your server-rerenders are coming from nuqs? Because as you said, and as it is, the default internal behaviour is to use the History API as recommended by Next.js for client-only updates of the URL. This will cause re-renders on the client (at least two as the URL udpate is asynchronous, so one for the optimistic state update and one when the URL finishes updating to get back in sync), but it should not trigger any re-renders on the server on its own, unless you opt-in to do so with |
Beta Was this translation helpful? Give feedback.
We can close this.
I found the issue it has nothing to do with neither Tanstack or nuqs... just my stupid *ss.. 😭.
In the docs for NextJs it does not say anything about you cant use ServerActions to fetch data. Even some youtubers have suggested doing this.
But I know better now, after I converted all my GET serverActions to be route-handlers all is good.
Thanks again for all your awesome responses!