SWR cached routes won't ever update content if response is empty or response is 404
Environment
##Reproduction env:
- Stackblitz
- Nitro v2.8.1
- Node v18.18.0
Env where encountered
- Operating System: Linux
- Node Version: v18.17.1
- Nuxt Version: 3.8.1
- CLI Version: 3.9.1
- Nitro Version: 2.7.2
- Package Manager: [email protected]
Reproduction
https://stackblitz.com/edit/github-wlae5p?file=routes%2Findex.ts
- Start the site either with
npm run devornpm build && node .output/server/index.mjs - Navigate to the
add-value-to-storageendpoint - Navigate to the
swrendpoint (will seenitro: is-awesome) - Navigate to the
not-swrendpoint (will seenitro: is-awesome) - Navigate to the
remove-value-from-storageendpoint - Navigate to the
not-swrroute and refresh until the cache expires - Will eventually get a blank response
- Navigate to the
swrendpoint - It'll continue to return the
nitro: is-awesomeresponse indefinitely.
Describe the bug
Routes cached by SWR cannot be updated to return empty/404 values without fully clearing the cache.
Description
We currently have a high-traffic Nuxt 3 site that's backed by a CMS. We have the pages and a Nuxt/Nitro API set to cache with SWR for 60 minutes.
When content editors delete a page, our CMS API will return null, which is what we'd expect our Nitro API to return. However, if the nitro API returns null or manually returns a 404 response, Nitro never seems to invalidate the SWR cache. This means we can't delete pages without manually clearing entries from the cache. This feels unexpected since there might be valid reasons for an API to return a 404 or 204 response.
Additional context
No response
Logs
No response
Why is this issue stale? This is a real-world issue.