nitro icon indicating copy to clipboard operation
nitro copied to clipboard

SWR cached routes won't ever update content if response is empty or response is 404

Open mdarrik opened this issue 2 years ago • 1 comments

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

  1. Start the site either with npm run dev or npm build && node .output/server/index.mjs
  2. Navigate to the add-value-to-storage endpoint
  3. Navigate to the swr endpoint (will see nitro: is-awesome)
  4. Navigate to the not-swr endpoint (will see nitro: is-awesome)
  5. Navigate to the remove-value-from-storage endpoint
  6. Navigate to the not-swr route and refresh until the cache expires
  7. Will eventually get a blank response
  8. Navigate to the swr endpoint
  9. It'll continue to return the nitro: is-awesome response 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

mdarrik avatar Dec 08 '23 21:12 mdarrik

Why is this issue stale? This is a real-world issue.

infabo avatar Dec 05 '25 12:12 infabo