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