Skip to content

Commit df6e864

Browse files
Jeffrey-ZuttJeffrey
authored andcommitted
feat: strip traceparent header from cachekey (#64499)
### What? We strip the `traceparent` header from the cache-key. ### Why? The traceparent header forms part of the W3C Trace Context standard, installed to track individual HTTP requests from start to end across multiple services. That means each individual HTTP request will have a unique traceparent value, reflecting its unique journey across servers and services. If we include the traceparent header in the cache key, the uniqueness of the traceparent means the cache key would always be different even for requests that should yield the same response. This would cause the cache to always miss and re-process the request. Effectively rendering fetch-cache useless. Co-authored-by: Jeffrey <[email protected]>
1 parent cd344c8 commit df6e864

File tree

1 file changed

+8
-3
lines changed
  • packages/next/src/server/lib/incremental-cache

1 file changed

+8
-3
lines changed

packages/next/src/server/lib/incremental-cache/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,19 @@ export class IncrementalCache implements IncrementalCacheType {
380380
}
381381
}
382382

383+
const headers =
384+
typeof (init.headers || {}).keys === 'function'
385+
? Object.fromEntries(init.headers as Headers)
386+
: Object.assign(init.headers || {}, {})
387+
388+
if ('traceparent' in headers) delete headers['traceparent']
389+
383390
const cacheString = JSON.stringify([
384391
MAIN_KEY_PREFIX,
385392
this.fetchCacheKeyPrefix || '',
386393
url,
387394
init.method,
388-
typeof (init.headers || {}).keys === 'function'
389-
? Object.fromEntries(init.headers as Headers)
390-
: init.headers,
395+
headers,
391396
init.mode,
392397
init.redirect,
393398
init.credentials,

0 commit comments

Comments
 (0)