Skip to content

fix(tag-cache): forward isStale() in withFilter#1189

Merged
vicb merged 2 commits intoopennextjs:mainfrom
fatihy101:fix/with-filter-forward-is-stale
Apr 11, 2026
Merged

fix(tag-cache): forward isStale() in withFilter#1189
vicb merged 2 commits intoopennextjs:mainfrom
fatihy101:fix/with-filter-forward-is-stale

Conversation

@fatihy101
Copy link
Copy Markdown
Contributor

Summary

The withFilter utility does not forward the optional isStale() method from the underlying tag cache implementation. This breaks SWR (stale-while-revalidate) support added in v1.19.0.

When using withFilter, globalThis.tagCache.isStale?.() always returns undefinedfalse, causing every revalidated entry to be treated as expired (immediate re-fetch) instead of stale (serve stale, revalidate in background).

Changes

  • Forward isStale() in withFilter, following the same conditional pattern used for getPathsByTags (only create the wrapper when the underlying tag cache provides it)
  • Add tests for isStale filtering, empty tag short-circuit, and undefined forwarding

How it was found

After upgrading to v1.19.0 and using withFilter + softTagFilter with doShardedTagCache, we observed that SWR never triggered. Tracing through the code revealed that withFilter's return object omits isStale, so the optional chain in @opennextjs/aws/utils/cache.js always falls back to false.

Closes #1187

The withFilter utility did not forward the optional isStale() method
from the underlying tag cache. This broke SWR (stale-while-revalidate)
support added in v1.19.0 — globalThis.tagCache.isStale?.() always
returned undefined when using withFilter, causing every revalidated
entry to be treated as expired instead of stale.

The fix follows the same pattern used for getPathsByTags: conditionally
create the isStale wrapper only when the underlying tag cache provides it.

Closes opennextjs#1187
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 10, 2026

🦋 Changeset detected

Latest commit: b15a531

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/cloudflare@1189

commit: b15a531

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Apr 11, 2026

Thanks for the issue and the fix @fatihy101 🙏

I'll add a changeset to the PR (running pnpm changeset) and merge.

@vicb vicb changed the title fix(tag-cache): forward isStale() in withFilter for SWR support fix(tag-cache): forward isStale() in withFilter Apr 11, 2026
Copy link
Copy Markdown
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 🙏

@vicb vicb merged commit 236ce14 into opennextjs:main Apr 11, 2026
7 checks passed
@fatihy101 fatihy101 deleted the fix/with-filter-forward-is-stale branch April 11, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

withFilter does not forward isStale(), breaking SWR support

2 participants