value changes even when on static build
Answered
NuclearMonkey posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
i don't understand why the static page changes the value when I click the home
102 Replies
![Image](https://cdn.discordapp.com/attachments/1223658418028544190/1223658541357731953/image.png?ex=661aa7d2&is=660832d2&hm=f374817fd6a73b550d457a2b4438480aab4de9df5a07b13258ee0a7a219833cb&)
value changes when I click on the home link
export default function PostsPage() {
function randomThreeDigitNumber() {
return Math.floor(Math.random() * (1000 - 100) + 100);
}
return (
<div>
PostsPage
<p>{randomThreeDigitNumber()}</p>
<p>{new Date().toISOString()}</p>
</div>
);
}
export default function Home() {
function randomThreeDigitNumber() {
return Math.floor(Math.random() * (1000 - 100) + 100);
}
return (
<div>
Home
<p>{randomThreeDigitNumber()}</p>
<p>{new Date().toISOString()}</p>
</div>
);
}
this build is on prod
@Arinji have you encountered this?
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
@NuclearMonkey <@890486507872342027> have you encountered this?
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
Dev mode dosent have agressive cache remember
It tries to give u updates values
Oh wait you on prod
One sec lemme give it a look
Looks to be a react thing, not a nextjs thing
React rerender the component remember, hence the numbers update
That's what changes the numbers
@NuclearMonkey can you show me what next build shows
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
i forgot to give the layout code
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import './globals.css';
import Link from 'next/link';
const inter = Inter({ subsets: ['latin'] });
export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>
<nav className="">[navbar]</nav>
<ul>
<li>
<Link href="/">Home</Link>
</li>
<li>
<Link href="/posts">About</Link>
</li>
</ul>
{children}
</body>
</html>
);
}
this only happens when you navigate via links
not via the URL bar
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
No like when you run npm run build
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
So when you go to /posts from / via the link you see the dates update right?
And if you refresh the page the date remains the same, then if you go back to / and then go to /posts from there the value changes
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
when I first go to the
/ route
route it gives 657 then when I pressed the navigation link that has an href of /
it then changes the 657 to 693![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
And if you refresh the page?
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
One sec, lemme get home and I can check it out
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
yes
it should be static right
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
@NuclearMonkey yes
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
are you sure you are on production?
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
yeah
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
tell me the commands you ran
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
npm run build and npm run start
do you see anything in your implementation different from this?
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
no
its basically the same
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
thats unusual, screenshare
dm me and i can join
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
@alfonsus another cache issue
when you are on / and you click on the home link.. the values update
is this a hydration thing? the / page gives 2 values
985 and 245, 245 seems to be the correct value since navigating from / to posts, then back to / gives 245
985 and 245, 245 seems to be the correct value since navigating from / to posts, then back to / gives 245
Answer
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
one is the cache of the whole page (.html)
one is the cache of the prefetched link (rsc)
i know its weird
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
wouldnt it be same though?
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
the content is the same its just that they rendered twice
because of partial rendering
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
wait ppr?
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
no
i dont think so
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
its still in canary right
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
see what kind of payload is returned when prefetching
/ (home)
from /about
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
@Arinji its still in canary right
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
like i said, ive experienced this issue from a while back
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
hm
wait one sec
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
is it pure html or RSC
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
rsc
,{"children":245}]
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
Yeah, they need to generate 2 version
One is the .html of the whole page, and the other is just the partial rendering, the soft navigation
Atleast thats how I understand it
CMIIW
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
hmm, looks liek it wasnt mentioned in the docs
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
But theyre all generated at the same time at build
Its very technical
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
does this happen because, next js generate an html file and a RSC file?
when next build right, it generates and html and rsc which look is json like
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
All the prefetches of static routes are also generated at build after the full route are generated
So after '/', generates
I assume they only generate twice per static route
So after '/', generates
/
from /about
, etc.I assume they only generate twice per static route
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
so when I clicked the root link it sends the rsc
so it changes
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
It receives rsc so it changed
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
because the random number is dynamic
it just gets 2 static values
one from the pregenerated html
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
no i mean the random number generator
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
one from the static rsc
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
@NuclearMonkey no i mean the random number generator
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
its still static, as per nextjs it gets cached
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
it generates 2 different number, the different for static html and diffrent for the RSC
is what im saying
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
yup, 2 different static numbers, thats the main difference
its static cause they wont change, but yes different in terms of each other
Im probs gonna look into this a bit more, but alfon should have solved your query
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
yeah that was also the theory i mentioned to you earlier
what alfonsus said
thanks for the help
its all making sense now
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
np, mark alfon's stuff as the soln
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
@alfonsus
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
This post is done, continue in discussion lols
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/b842ccabbc9aad7d32fc17b299aadcd2.webp?size=256)
kk
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
@alfonsus is there a way to make to make the html and rsc the same?
![Avatar](https://cdn.discordapp.com/avatars/371849330585370626/d455ae9da085477f594f8aaa12768025.webp?size=256)
@NuclearMonkey <@194128415954173952> is there a way to make to make the html and rsc the same?
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/156028f551218bc4a7d1d33c4321be8c.webp?size=256)
try using cache() or unstable_cache()