Next.js Discord

Discord Forum

server component doesnt refetch on navigation

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
why?

32 Replies

Giant pandaOP
export const dynamic = 'force-dynamic'
this doesnt do anything
would you mind sharing a bit of code?
Giant pandaOP
revalidation is required. i love next more and more by day
even then
i have a problem
when i do revalidatePath the whole page flashes
which i do not want
i need it to happen in the background
Giant pandaOP
is there a way for this happen?
Because I do not need immediate revalidation, however it must be so that if a user navigates to Y page when they return to X the data for X is updated
I cant find any way to force this without revalidatePath...
Giant pandaOP
bump
Giant pandaOP
bump
Siamese Crocodile
lol yeah its annoying i have the same bug
export const dynamic = 'force-dynamic'
is that suppose dto fix it @Giant panda
?
you must revalidate
as far as i know that is the only way
very annoying
Siamese Crocodile
what the fk
Giant pandaOP
maybe theres some other way, i dont know
cause im having a case where i go to a different page
and then i go back to the old one
and the data there is empty cause its old
so now i just revalidatePath
but
that causes an issue where it seems to flash the page for some reason
Giant pandaOP
bump
American Crow
Only thing i can think off:

page.tsx
import ClientComponent from "@/app/test-fetch/client-component"
import Link from "next/link"

export default async function TestFetchOnBackButton() {
  const response = await fetch("http://worldtimeapi.org/api/timezone/Europe/Berlin", {
     cache: "no-store",
    
   })
   const { utc_datetime } = await response.json()

   return (
      <div>
        <ClientComponent utc_datetime={utc_datetime} />
       
         <Link
            className="bg-blue-500 p-4"
            href="/"
         >
            Go Homepage
         </Link>
      </div>
   )
}

ClientComponent.tsx
"use client"

import { useRouter } from "next/navigation"
import { useEffect } from "react"

export default function ClientComponent({ utc_datetime }) {
   const router = useRouter()

   useEffect(() => {
      router.refresh()
   }, [router])

   return <div className="my-10">Current time in Berlin: {utc_datetime}</div>
}