why are page.tsx files that use "use client" doesn't get cached in the router cache?
Answered
NuclearMonkey posted this in #help-forum
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?
23 Replies
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
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
Arinji
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
NuclearMonkeyOP
this on dev mode right?
Arinji
yup
first requests for all pages take a while
NuclearMonkeyOP
wait ill create sandbox
NuclearMonkeyOP
Arinji
yup thats normal
router cache caches the fetch data
not the actual react components
one sec lemme show docs
Arinji
Answer
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