Next.js Discord

Discord Forum

why are page.tsx files that use "use client" doesn't get cached in the router cache?

Answered
NuclearMonkey posted this in #help-forum
Open in Discord
Avatar
NuclearMonkeyOP
why are page.tsx files that use "use client" doesn't get cached in the router cache? but if it a server component it is cache in the router cache? why is this?
Answered by Arinji
Image
View full answer

23 Replies

Avatar
Arinji
Router cache dosent cache the actual ui, its for the data. Im guessign in a client page you fetch data in a useEffect? @NuclearMonkey
also dont use client pages
Avatar
NuclearMonkeyOP
router cache caches the RSC payload right, but why doesn't it cache the client component if the page was a client? I was just curious about this, that's why I was testing putting 'use client' on page
Avatar
Arinji
https://ccfsss-3000.csb.app/

looks like it does ( i had to check since i dont use client pages much)
export default function Home() {
  const [loaded, setLoaded] = useState(false);
  useEffect(() => {
    new Promise((r) => setTimeout(r, 3000));
    setLoaded(true);
  }, []);
  return (
    <div>
      {loaded && (
        <div className="flex flex-col">
          CLIENT PAGE <Link href="/">HOME PAGE</Link>
          <Link href="/server">SERVER PAGE</Link>
        </div>
      )}
    </div>
  );
}
thas my client page
Avatar
NuclearMonkeyOP
this on dev mode right?
Avatar
Arinji
yup
Image
first requests for all pages take a while
Avatar
NuclearMonkeyOP
wait ill create sandbox
Avatar
Arinji
i already have oe
one
Avatar
NuclearMonkeyOP
Avatar
Arinji
yup thats normal
router cache caches the fetch data
not the actual react components
one sec lemme show docs
Avatar
Arinji
Image
Answer
Avatar
Arinji
they are 2 seperate steps, your client page is the 3rd part
it wont just cache react and its hooks since that would lead to a whole lot of bugs
it will cache stuff like fetching data, resolving a promise etc