#Threeeaaadddd
1 messages · Page 1 of 1 (latest)
yo
and Post is page.tsx correct?
ofc
but?
so the issue here is that you need to actually poll the page for it to revalidate
i would do a setInterval (janky but this is the example)
and poll the page every couple seconds
wdym
revalidate 0, and refresh on new posts, but its never gonna get new posts
so its never gonna refresh
why
nextjs docs says otherwise
because something needs to initiate the action
the useEffect
the use effect isnt going to trigger but 1 time
unless EVERY SINGLE refresh has a new change
cuz the post will stay the same until refresh
right?
right!
so we cry about it?
so do a setInterval
wont that be the same is reloading
iin this basic example yes
but
if you wrap the feed as a client component that keeps a “newest post” state
that's kinda janky what do ppl usually do instead of polling or websockets
you can implement a “show new posts” button
that way it does get the new posts but doesnt add them to the dom till the user asks it to
like the blue bird

but that's adding sth to solve it, cant we do it normally in nextjs without web sockets
so that's if i use route.refresh
websockets == top tier | data polling == mid tier | route refresh interval == low tier
those are the 3 ways
honestly
but polling wont work
in my example
cuz it needs a trigger
but how do ppl use polling
yes. that was my original point
my original point was that you want client only features but your data is server side
you could make an api route and query your own api as a client component
that just gives a post ID
so if the data is sever side i cant do polling
and if the post id !== local post id then router refresh
u mean route handlers???
yes… an api route. dont be pedantic mf 😂
hahaa
ROUTE HANDLERS
thanks man
so much valiable stuff
its new logic. so everyone is trying to learn how to slice the pie the right way together
so usually to do polling u need an "api route" to update the data on the client
which is kinda bad for nextjs cuz that whole point is stuff to be server
but whatever
right. imo “live” stuff just isnt gonna get the server benefits of nextjs. it is what it is
that's the hard truth
unless we use server actions
which i wont
too lazy to learn
oh
i see
so either refresh or api route with polling or web sockets
these are the options
think of server actions as a shortcut api without needing to write out a whole api to make a server call
or i can do a huge iq move
just update the state visually
the like btn
and the server will update
without them connecting
i see
yeah that could work too. could use server for initial state then hand it off to api route polling for live state
yes
do u have blue bird?
btw thanks dude
understood a lot
si. im the same name everywhere
btw for setting intervals how would u do that
how often do you wanna check?
5 seconds
ts or just js
ye where do i put it
inside your useEffect
const handle = setInterval(() => {
fetch("https://chubbybunny.com/api/posts?userId=tinyTim")
.then(res => res.text().then(
newPostId => {
if (newPostId !== latestPostId) {
setLatestPostId(newPostId)
}
})
), 5_000)
return () => {
clearInterval(handle)
}
sorry had to post so i could see where the formatting was at
phone coding hard
close thread
it will hide an hour after the last message in settings
it didnt
an hour passed
nono
i am saying i just set it for me… but i think its per person
unless i have unilateral control since i made the thread
ooo good catch