Open huumn opened 9 months ago
If anyone runs into this problem and has a service worker, we are planning to workaround it with a workbox plugin:
fetchDidSucceed: async ({ request, response, event, state }) => {
if (
response.ok &&
request.headers.get('x-nextjs-data') &&
response.headers.get('x-nextjs-matched-path') &&
response.headers.get('content-type') === 'application/json' &&
response.headers.get('content-length') === '2' &&
response.status === 200) {
console.log('service worker detected a successful yet empty nextjs SSR data response')
console.log('nextjs has a bug where it returns a 200 with empty data when it should return a 404')
console.log('see https://github.com/vercel/next.js/issues/56852')
console.log('HACK ... intercepting response and returning 404')
const headers = new Headers(response.headers)
headers.delete('x-nextjs-matched-path')
headers.delete('content-type')
headers.delete('content-length')
return new Response(null, {
status: 404,
statusText: 'Not Found',
headers,
ok: false
})
}
return response
}
}
Hi, I have the same problem: get 200 status with empty response after every deployment - even when I specifically ignore _next/data requests in middleware matcher.
Also seeing this issue
In version 13.5.6, the same issue was discovered, so we downgraded to version 13.4.10 to resolve it. However, we are unsure how many recent versions this problem persists in.. 😢
Link to the code that reproduces this issue
https://github.com/huumn/repro-nextjs-data-404-resp-200
To Reproduce
This is recreating fetching serverside props on client navigation.
Any
/_next/data/
path exhibits this behavior but this is a practical problem as these paths change on deployment, ie/_next/data/:deployment_id/:path*
. If the middleware.js file is removed, the application 404s as expected.Current vs. Expected behavior
Current: returns 200 and an empty json object in body so client thinks route is good and the data is just empty Expected: returns 404 so client can refresh routes
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Data fetching (gS(S)P, getInitialProps)
Additional context
Anytime we deploy in prod, our customers using pwas or those actively online get served stale data when navigating until they hard close or refresh respectively.
I believe the 404 is getting rewritten to 200 here: https://github.com/vercel/next.js/blob/c6fe20a31ff4f62ee75c08cd0eae9ceaba7ec50d/packages/next/src/server/lib/router-server.ts#L205-L215