After the fact tagging #76667
Unanswered
Jordaneisenburger
asked this question in
App Router
Replies: 1 comment
-
|
Well a patch seems to work, what can go wrong right? --- a/node_modules/next/dist/esm/server/use-cache/use-cache-wrapper.js
+++ b/node_modules/next/dist/esm/server/use-cache/use-cache-wrapper.js
+ const filteredArgs = args.filter(arg =>
+ // if arg is an object and has the property, filter it out
+ !(typeof arg === 'object' && arg !== null && 'bearerToken' in arg)
+ );
+
const cacheKeyParts = [
buildId,
hmrRefreshHash,
id,
- args
+ filteredArgs
]; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goal
We want to tag fetch requests after they have completed, so we can later invalidate or revalidate caches based on those tags. Currently, Next.js only documents how to add tags at request time via
fetch(..., { next: { tags } }), rather than post-fetch. The only way to tag a request after it returns is usingcacheTag(), but callingcacheTag()requires'use cache'.That introduces a problem:
'use cache'function at all, or if you do, it ends up in the cache key.Why would you want to include a bearer token in a cacheable request?
In an e-commerce scenario, multiple logged-in customers might share the same cache group. Suppose customer A initiates the first request (which isn’t cached) and receives fresh data from Adobe Commerce. Because the data is tied to a particular cache group, future requests for that same group can then be served instantly from the cache. In that initial request, however, a bearer token is typically required for authentication and to associate the response with the correct cache group.
Hence the dilemma:
'use cache'would capture that token as part of the cache key—which is both a security and a maintainability concern.This creates a tension between wanting to use
cacheTag()(and thus'use cache') for tagging after a request completes, and needing to supply a bearer token (without making it part of the cache key).Passing a function to the fetch function as a prop throws this errror: (as also highlighted here: #71859)
As an example, i need below code to not add
bearerTokento the cache keyWould love any pointers on how to tag these requests after the data has been fetched.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions