fix(tag-cache): forward isStale() in withFilter#1189
Merged
vicb merged 2 commits intoopennextjs:mainfrom Apr 11, 2026
Merged
Conversation
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 detectedLatest commit: b15a531 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
Contributor
|
Thanks for the issue and the fix @fatihy101 🙏 I'll add a changeset to the PR (running |
isStale() in withFilter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
withFilterutility does not forward the optionalisStale()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 returnsundefined→false, causing every revalidated entry to be treated as expired (immediate re-fetch) instead of stale (serve stale, revalidate in background).Changes
isStale()inwithFilter, following the same conditional pattern used forgetPathsByTags(only create the wrapper when the underlying tag cache provides it)isStalefiltering, empty tag short-circuit, and undefined forwardingHow it was found
After upgrading to v1.19.0 and using
withFilter+softTagFilterwithdoShardedTagCache, we observed that SWR never triggered. Tracing through the code revealed thatwithFilter's return object omitsisStale, so the optional chain in@opennextjs/aws/utils/cache.jsalways falls back tofalse.Closes #1187