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
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
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
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
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
this on dev mode right?
Avatar
yup
Image
first requests for all pages take a while
Avatar
wait ill create sandbox
Avatar
i already have oe
one
Avatar
yup thats normal
router cache caches the fetch data
not the actual react components
one sec lemme show docs
Avatar
Image
Answer
Avatar
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