Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a79950dc
Unverified
Commit
a79950dc
authored
Feb 14, 2025
by
Boris Besemer
Committed by
GitHub
Feb 14, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove tracestate header from fetch cache key (#76041)
parent
a8d36ddb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
14 deletions
+73
-14
index.ts
packages/next/src/server/lib/incremental-cache/index.ts
+3
-0
app-static.test.ts
test/e2e/app-dir/app-static/app-static.test.ts
+19
-14
page.tsx
...r/app-static/app/strip-w3c-trace-context-headers/page.tsx
+51
-0
No files found.
packages/next/src/server/lib/incremental-cache/index.ts
View file @
a79950dc
...
@@ -354,7 +354,10 @@ export class IncrementalCache implements IncrementalCacheType {
...
@@ -354,7 +354,10 @@ export class IncrementalCache implements IncrementalCacheType {
? Object.fromEntries(init.headers as Headers)
? Object.fromEntries(init.headers as Headers)
: Object.assign({}, init.headers)
: Object.assign({}, init.headers)
// w3c trace context headers can break request caching and deduplication
// so we remove them from the cache key
if ('traceparent' in headers) delete headers['traceparent']
if ('traceparent' in headers) delete headers['traceparent']
if ('tracestate' in headers) delete headers['tracestate']
const cacheString = JSON.stringify([
const cacheString = JSON.stringify([
MAIN_KEY_PREFIX,
MAIN_KEY_PREFIX,
...
...
test/e2e/app-dir/app-static/app-static.test.ts
View file @
a79950dc
...
@@ -105,20 +105,25 @@ describe('app-dir static/dynamic handling', () => {
...
@@ -105,20 +105,25 @@ describe('app-dir static/dynamic handling', () => {
expect
(
initialRouteData
).
not
.
toEqual
(
newRouteData
)
expect
(
initialRouteData
).
not
.
toEqual
(
newRouteData
)
})
})
it
(
'should still cache even though the
`traceparent` header was
different'
,
async
()
=>
{
it
(
'should still cache even though the
W3C trace context headers `traceparent` and `tracestate` were
different'
,
async
()
=>
{
const
res
=
await
next
.
fetch
(
'/strip-
header-traceparent
'
)
const
res
=
await
next
.
fetch
(
'/strip-
w3c-trace-context-headers
'
)
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
status
).
toBe
(
200
)
const
html
=
await
res
.
text
()
const
html
=
await
res
.
text
()
const
$
=
cheerio
.
load
(
html
)
const
$
=
cheerio
.
load
(
html
)
const
data1
=
$
(
'#data1'
).
text
()
const
traceparent1
=
$
(
'#traceparent1'
).
text
()
const
data2
=
$
(
'#data2'
).
text
()
const
traceparent2
=
$
(
'#traceparent2'
).
text
()
expect
(
data1
).
toBeTruthy
()
const
tracestate1
=
$
(
'#tracestate1'
).
text
()
expect
(
data1
).
toBe
(
data2
)
const
tracestate2
=
$
(
'#tracestate2'
).
text
()
expect
(
traceparent1
).
toBeTruthy
()
expect
(
traceparent1
).
toBe
(
traceparent2
)
expect
(
tracestate1
).
toBeTruthy
()
expect
(
tracestate1
).
toBe
(
tracestate2
)
const
echoedHeaders
=
JSON
.
parse
(
$
(
'#echoedHeaders'
).
text
())
const
echoedHeaders
=
JSON
.
parse
(
$
(
'#echoedHeaders'
).
text
())
expect
(
echoedHeaders
.
headers
.
traceparent
).
toEqual
(
'C'
)
expect
(
echoedHeaders
.
headers
.
traceparent
).
toEqual
(
'A'
)
expect
(
echoedHeaders
.
headers
.
tracestate
).
toEqual
(
'A'
)
})
})
// Runtime logs aren't queryable in deploy mode
// Runtime logs aren't queryable in deploy mode
...
@@ -1030,10 +1035,10 @@ describe('app-dir static/dynamic handling', () => {
...
@@ -1030,10 +1035,10 @@ describe('app-dir static/dynamic handling', () => {
"static-to-dynamic-error-forced/[id]/page_client-reference-manifest.js",
"static-to-dynamic-error-forced/[id]/page_client-reference-manifest.js",
"static-to-dynamic-error/[id]/page.js",
"static-to-dynamic-error/[id]/page.js",
"static-to-dynamic-error/[id]/page_client-reference-manifest.js",
"static-to-dynamic-error/[id]/page_client-reference-manifest.js",
"strip-
header-traceparent
.html",
"strip-
w3c-trace-context-headers
.html",
"strip-
header-traceparent
.rsc",
"strip-
w3c-trace-context-headers
.rsc",
"strip-
header-traceparent
/page.js",
"strip-
w3c-trace-context-headers
/page.js",
"strip-
header-traceparent
/page_client-reference-manifest.js",
"strip-
w3c-trace-context-headers
/page_client-reference-manifest.js",
"too-many-cache-tags/page.js",
"too-many-cache-tags/page.js",
"too-many-cache-tags/page_client-reference-manifest.js",
"too-many-cache-tags/page_client-reference-manifest.js",
"unstable-cache/dynamic-undefined/page.js",
"unstable-cache/dynamic-undefined/page.js",
...
@@ -2192,7 +2197,7 @@ describe('app-dir static/dynamic handling', () => {
...
@@ -2192,7 +2197,7 @@ describe('app-dir static/dynamic handling', () => {
"initialRevalidateSeconds": false,
"initialRevalidateSeconds": false,
"srcRoute": "/ssg-draft-mode/[[...route]]",
"srcRoute": "/ssg-draft-mode/[[...route]]",
},
},
"/strip-
header-traceparent
": {
"/strip-
w3c-trace-context-headers
": {
"allowHeader": [
"allowHeader": [
"host",
"host",
"x-matched-path",
"x-matched-path",
...
@@ -2201,7 +2206,7 @@ describe('app-dir static/dynamic handling', () => {
...
@@ -2201,7 +2206,7 @@ describe('app-dir static/dynamic handling', () => {
"x-next-revalidated-tags",
"x-next-revalidated-tags",
"x-next-revalidate-tag-token",
"x-next-revalidate-tag-token",
],
],
"dataRoute": "/strip-
header-traceparent
.rsc",
"dataRoute": "/strip-
w3c-trace-context-headers
.rsc",
"experimentalBypassFor": [
"experimentalBypassFor": [
{
{
"key": "Next-Action",
"key": "Next-Action",
...
@@ -2214,7 +2219,7 @@ describe('app-dir static/dynamic handling', () => {
...
@@ -2214,7 +2219,7 @@ describe('app-dir static/dynamic handling', () => {
},
},
],
],
"initialRevalidateSeconds": 50,
"initialRevalidateSeconds": 50,
"srcRoute": "/strip-
header-traceparent
",
"srcRoute": "/strip-
w3c-trace-context-headers
",
},
},
"/unstable-cache/fetch/no-cache": {
"/unstable-cache/fetch/no-cache": {
"allowHeader": [
"allowHeader": [
...
...
test/e2e/app-dir/app-static/app/strip-
header-traceparent
/page.tsx
→
test/e2e/app-dir/app-static/app/strip-
w3c-trace-context-headers
/page.tsx
View file @
a79950dc
export
default
async
function
Page
()
{
export
default
async
function
Page
()
{
const
data
1
=
await
fetch
(
const
traceparent
1
=
await
fetch
(
'https://next-data-api-endpoint.vercel.app/api/random'
,
'https://next-data-api-endpoint.vercel.app/api/random'
,
{
{
headers
:
{
traceparent
:
'A'
},
headers
:
{
traceparent
:
'A'
},
...
@@ -7,7 +7,7 @@ export default async function Page() {
...
@@ -7,7 +7,7 @@ export default async function Page() {
}
}
).
then
((
res
)
=>
res
.
text
())
).
then
((
res
)
=>
res
.
text
())
const
data
2
=
await
fetch
(
const
traceparent
2
=
await
fetch
(
'https://next-data-api-endpoint.vercel.app/api/random'
,
'https://next-data-api-endpoint.vercel.app/api/random'
,
{
{
headers
:
{
traceparent
:
'B'
},
headers
:
{
traceparent
:
'B'
},
...
@@ -15,18 +15,36 @@ export default async function Page() {
...
@@ -15,18 +15,36 @@ export default async function Page() {
}
}
).
then
((
res
)
=>
res
.
text
())
).
then
((
res
)
=>
res
.
text
())
const
tracestate1
=
await
fetch
(
'https://next-data-api-endpoint.vercel.app/api/random'
,
{
headers
:
{
tracestate
:
'B'
},
next
:
{
revalidate
:
50
},
}
).
then
((
res
)
=>
res
.
text
())
const
tracestate2
=
await
fetch
(
'https://next-data-api-endpoint.vercel.app/api/random'
,
{
headers
:
{
tracestate
:
'B'
},
next
:
{
revalidate
:
50
},
}
).
then
((
res
)
=>
res
.
text
())
const
echoedHeaders
=
await
fetch
(
const
echoedHeaders
=
await
fetch
(
'https://next-data-api-endpoint.vercel.app/api/echo-headers'
,
'https://next-data-api-endpoint.vercel.app/api/echo-headers'
,
{
{
headers
:
{
traceparent
:
'
C
'
},
headers
:
{
traceparent
:
'
A'
,
tracestate
:
'A
'
},
next
:
{
revalidate
:
50
},
next
:
{
revalidate
:
50
},
}
}
).
then
((
res
)
=>
res
.
text
())
).
then
((
res
)
=>
res
.
text
())
return
(
return
(
<>
<>
<
p
id=
"data1"
>
{
data1
}
</
p
>
<
p
id=
"traceparent1"
>
{
traceparent1
}
</
p
>
<
p
id=
"data2"
>
{
data2
}
</
p
>
<
p
id=
"traceparent2"
>
{
traceparent2
}
</
p
>
<
p
id=
"tracestate1"
>
{
tracestate1
}
</
p
>
<
p
id=
"tracestate2"
>
{
tracestate2
}
</
p
>
<
p
id=
"echoedHeaders"
>
{
echoedHeaders
}
</
p
>
<
p
id=
"echoedHeaders"
>
{
echoedHeaders
}
</
p
>
</>
</>
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment