Skip to content

Commit c1ca6ac

Browse files
Jeffrey-ZuttJeffreyijjk
authored
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 ea0f516 commit c1ca6ac

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export class IncrementalCache implements IncrementalCacheType {
388388
const headers =
389389
typeof (init.headers || {}).keys === 'function'
390390
? Object.fromEntries(init.headers as Headers)
391-
: Object.assign(init.headers || {}, {})
391+
: Object.assign({}, init.headers)
392392

393393
if ('traceparent' in headers) delete headers['traceparent']
394394

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

Lines changed: 36 additions & 0 deletions
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)
@@ -822,6 +838,10 @@ createNextDescribe(
822838
"static-to-dynamic-error-forced/[id]/page_client-reference-manifest.js",
823839
"static-to-dynamic-error/[id]/page.js",
824840
"static-to-dynamic-error/[id]/page_client-reference-manifest.js",
841+
"strip-header-traceparent.html",
842+
"strip-header-traceparent.rsc",
843+
"strip-header-traceparent/page.js",
844+
"strip-header-traceparent/page_client-reference-manifest.js",
825845
"too-many-cache-tags/page.js",
826846
"too-many-cache-tags/page_client-reference-manifest.js",
827847
"unstable-cache/dynamic-undefined/page.js",
@@ -1544,6 +1564,22 @@ createNextDescribe(
15441564
"initialRevalidateSeconds": false,
15451565
"srcRoute": "/ssg-draft-mode/[[...route]]",
15461566
},
1567+
"/strip-header-traceparent": {
1568+
"dataRoute": "/strip-header-traceparent.rsc",
1569+
"experimentalBypassFor": [
1570+
{
1571+
"key": "Next-Action",
1572+
"type": "header",
1573+
},
1574+
{
1575+
"key": "content-type",
1576+
"type": "header",
1577+
"value": "multipart/form-data;.*",
1578+
},
1579+
],
1580+
"initialRevalidateSeconds": 50,
1581+
"srcRoute": "/strip-header-traceparent",
1582+
},
15471583
"/variable-config-revalidate/revalidate-3": {
15481584
"dataRoute": "/variable-config-revalidate/revalidate-3.rsc",
15491585
"experimentalBypassFor": [
Lines changed: 33 additions & 0 deletions
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)