Skip to content

Commit 73c2d63

Browse files
Jeffrey-ZuttJeffreyijjk
authored andcommitted
fix: remove traceparent from cachekey should not remove traceparent from original object (#64727)
### What? I submitted PR #64499 , it got merged, but it contains a mistake. I'm terribly sorry about this! By removing the traceparent from the cachekey, we mistakenly removed the header from the original object. Causing the actual request to be executed without the traceparent header. ### Why? Creating a cachekey should not alter the original object. ### How? Flip the arguments for Object.assign --------- Co-authored-by: Jeffrey <[email protected]> Co-authored-by: JJ Kasper <[email protected]>
1 parent dd44191 commit 73c2d63

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export class IncrementalCache implements IncrementalCacheType {
383383
const headers =
384384
typeof (init.headers || {}).keys === 'function'
385385
? Object.fromEntries(init.headers as Headers)
386-
: Object.assign(init.headers || {}, {})
386+
: Object.assign({}, init.headers)
387387

388388
if ('traceparent' in headers) delete headers['traceparent']
389389

test/e2e/app-dir/app-static/app-static.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ createNextDescribe(
4040
}
4141
})
4242

43+
it('should still cache even though the `traceparent` header was different', async () => {
44+
const res = await next.fetch('/strip-header-traceparent')
45+
expect(res.status).toBe(200)
46+
47+
const html = await res.text()
48+
const $ = cheerio.load(html)
49+
50+
const data1 = $('#data1').text()
51+
const data2 = $('#data2').text()
52+
expect(data1).toBeTruthy()
53+
expect(data1).toBe(data2)
54+
55+
const echoedHeaders = JSON.parse($('#echoedHeaders').text())
56+
expect(echoedHeaders.headers.traceparent).toEqual('C')
57+
})
58+
4359
it('should warn for too many cache tags', async () => {
4460
const res = await next.fetch('/too-many-cache-tags')
4561
expect(res.status).toBe(200)
@@ -790,6 +806,10 @@ createNextDescribe(
790806
"static-to-dynamic-error-forced/[id]/page_client-reference-manifest.js",
791807
"static-to-dynamic-error/[id]/page.js",
792808
"static-to-dynamic-error/[id]/page_client-reference-manifest.js",
809+
"strip-header-traceparent.html",
810+
"strip-header-traceparent.rsc",
811+
"strip-header-traceparent/page.js",
812+
"strip-header-traceparent/page_client-reference-manifest.js",
793813
"too-many-cache-tags/page.js",
794814
"too-many-cache-tags/page_client-reference-manifest.js",
795815
"unstable-cache/dynamic-undefined/page.js",
@@ -1512,6 +1532,22 @@ createNextDescribe(
15121532
"initialRevalidateSeconds": false,
15131533
"srcRoute": "/ssg-draft-mode/[[...route]]",
15141534
},
1535+
"/strip-header-traceparent": {
1536+
"dataRoute": "/strip-header-traceparent.rsc",
1537+
"experimentalBypassFor": [
1538+
{
1539+
"key": "Next-Action",
1540+
"type": "header",
1541+
},
1542+
{
1543+
"key": "content-type",
1544+
"type": "header",
1545+
"value": "multipart/form-data;.*",
1546+
},
1547+
],
1548+
"initialRevalidateSeconds": 50,
1549+
"srcRoute": "/strip-header-traceparent",
1550+
},
15151551
"/variable-config-revalidate/revalidate-3": {
15161552
"dataRoute": "/variable-config-revalidate/revalidate-3.rsc",
15171553
"experimentalBypassFor": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export default async function Page() {
2+
const data1 = await fetch(
3+
'https://next-data-api-endpoint.vercel.app/api/random',
4+
{
5+
headers: { traceparent: 'A' },
6+
next: { revalidate: 50 },
7+
}
8+
).then((res) => res.text())
9+
10+
const data2 = await fetch(
11+
'https://next-data-api-endpoint.vercel.app/api/random',
12+
{
13+
headers: { traceparent: 'B' },
14+
next: { revalidate: 50 },
15+
}
16+
).then((res) => res.text())
17+
18+
const echoedHeaders = await fetch(
19+
'https://next-data-api-endpoint.vercel.app/api/echo-headers',
20+
{
21+
headers: { traceparent: 'C' },
22+
next: { revalidate: 50 },
23+
}
24+
).then((res) => res.text())
25+
26+
return (
27+
<>
28+
<p id="data1">{data1}</p>
29+
<p id="data2">{data2}</p>
30+
<p id="echoedHeaders">{echoedHeaders}</p>
31+
</>
32+
)
33+
}

0 commit comments

Comments
 (0)