pull down to refresh
81 sats \ 24 replies \ @k00b 14 Oct 2023 \ on: Stacker Saloon
Continuing hunting for this caching issue that is destroying my mind body and soul or write the saturday newsletter?
So it's not confirmed that vercel/next.js#51823 is causing this as mentioned in the ticket?
reply
I'm pretty sure that's not the issue at this point. Let's say we're running deployment id
A
, when we load pages, the path requested for SSR data will look like .../A/...json
. All the appropriate cache headers are set, e.g. no-store, no-cache
.When we deploy deployment id
B
, the browser/pwa (unless its a fresh navigation or reload) continues to request .../A/...json
on navigations. Even though .../A/...json
doesn't actually exist, ie its a 404 if visited directly, the service worker returns an empty response with status 200 ... so effectively all the data is stale.You can recreate locally by building production builds and manually altering the deployment id between builds.
What's weird is that the service worker doesn't appear to be serving the empty responses from its cache (at least it doesn't say that it is) ... so where are they coming from? Again, visiting the path directly results in a 404 so nextjs isn't sending the 200s.
It has to either come from the service worker or the browser's cache but neither of them should be storing it.
reply
I'm pretty sure I've ruled out the service worker returning stale responses under normal circumstances because if I manually call
fetch('.../A/...json')
with default options in the browser console, then the service worker reports 404.So it maybe nextjs calling fetch with weird options that's causing the issue.
reply
Looks like it is nextjs. It's calling fetch with a
X-Nextjs-Data: 1
header. If I remove the header, it 404's like it should.Here it turns a 404 to a 200 on the server: https://github.com/vercel/next.js/blob/c6fe20a31ff4f62ee75c08cd0eae9ceaba7ec50d/packages/next/src/server/lib/router-server.ts#L205
reply
If you run this in the browser console while on
https://stacker.news
it'll return 200 for an arbitrary data request.const headers = new Headers() headers.append('X-Nextjs-Data', '1') fetch('https://stacker.news/_next/data/this_doesnt_exist.json', { headers }).then(console.log)
reply
If I remove the middleware it works as expected and 404s.
I guess I should report this a bug to nextjs.
I see, must be related to how their client side navigation works since only during client side navigation, these
/_next/data/
routes are called, I think.deleted by author
deleted by author
reply
deleted by author
reply
what good movie should I watch tonight?
reply
deleted by author
reply
I think I watched this one too
reply
deleted by author
reply
watched, great movie!
deleted by author