Nextjs link tag preserving state when link to same page

I have a Navbar which is a server component that utilizes the next.js <Link>. I have a route (page) that eventually renders a client component with some state. If I call setState and then try to click on the Link from the navbar (href points to the same page), the state from the client component is preserved. Anyone know how I can force this rerender/reset of state?
5 Replies
Josh
Josh14mo ago
next is smart enough to try and preserve state as much as possible between navigation so in order to listen for that event, add an event listener onClick onto that nav component and trigger whatever side effects using that
!Stan_---__-
!Stan_---__-OP14mo ago
ok i think i understand haha, i assume u mean the side effect being the resetting of the client state in the client component?
Josh
Josh14mo ago
yep
!Stan_---__-
!Stan_---__-OP14mo ago
shit that means i have to make my page a client whyyyyyyyyyyyy
!Stan_---__-
!Stan_---__-OP14mo ago
@Josh thanks for the help yesterday, i found this https://www.youtube.com/watch?v=_yhSh4g0NSk insane caching messing everything up, I think i'll just convert it to an anchor tag and do a full page refresh (which i dont think i mind)
Josh tried coding
YouTube
I Hate Next.js 13 Caching Even More Now
I prefer Next over all the other frameworks. Makes me and many others insanely productive. But caching in Next.js 13? Aw man it sucks. Glad they acknowledge the problem with their article, but it's really frustrating. Article: https://nextjs.org/docs/app/building-your-application/caching -- my links Next.js SaaS: https://splitter.gg Discord: h...
Want results from more Discord servers?
Add your server