Unverified Commit c1ca6ac9 authored by Jeffrey Zutt's avatar Jeffrey Zutt Committed by GitHub

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: 's avatarJeffrey <jeffrey@jeffreyzutt.nl>
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent ea0f5163
...@@ -388,7 +388,7 @@ export class IncrementalCache implements IncrementalCacheType { ...@@ -388,7 +388,7 @@ export class IncrementalCache implements IncrementalCacheType {
const headers = const headers =
typeof (init.headers || {}).keys === 'function' typeof (init.headers || {}).keys === 'function'
? Object.fromEntries(init.headers as Headers) ? Object.fromEntries(init.headers as Headers)
: Object.assign(init.headers || {}, {}) : Object.assign({}, init.headers)
if ('traceparent' in headers) delete headers['traceparent'] if ('traceparent' in headers) delete headers['traceparent']
......
...@@ -40,6 +40,22 @@ createNextDescribe( ...@@ -40,6 +40,22 @@ createNextDescribe(
} }
}) })
it('should still cache even though the `traceparent` header was different', async () => {
const res = await next.fetch('/strip-header-traceparent')
expect(res.status).toBe(200)
const html = await res.text()
const $ = cheerio.load(html)
const data1 = $('#data1').text()
const data2 = $('#data2').text()
expect(data1).toBeTruthy()
expect(data1).toBe(data2)
const echoedHeaders = JSON.parse($('#echoedHeaders').text())
expect(echoedHeaders.headers.traceparent).toEqual('C')
})
it('should warn for too many cache tags', async () => { it('should warn for too many cache tags', async () => {
const res = await next.fetch('/too-many-cache-tags') const res = await next.fetch('/too-many-cache-tags')
expect(res.status).toBe(200) expect(res.status).toBe(200)
...@@ -822,6 +838,10 @@ createNextDescribe( ...@@ -822,6 +838,10 @@ createNextDescribe(
"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-header-traceparent.rsc",
"strip-header-traceparent/page.js",
"strip-header-traceparent/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",
...@@ -1544,6 +1564,22 @@ createNextDescribe( ...@@ -1544,6 +1564,22 @@ createNextDescribe(
"initialRevalidateSeconds": false, "initialRevalidateSeconds": false,
"srcRoute": "/ssg-draft-mode/[[...route]]", "srcRoute": "/ssg-draft-mode/[[...route]]",
}, },
"/strip-header-traceparent": {
"dataRoute": "/strip-header-traceparent.rsc",
"experimentalBypassFor": [
{
"key": "Next-Action",
"type": "header",
},
{
"key": "content-type",
"type": "header",
"value": "multipart/form-data;.*",
},
],
"initialRevalidateSeconds": 50,
"srcRoute": "/strip-header-traceparent",
},
"/variable-config-revalidate/revalidate-3": { "/variable-config-revalidate/revalidate-3": {
"dataRoute": "/variable-config-revalidate/revalidate-3.rsc", "dataRoute": "/variable-config-revalidate/revalidate-3.rsc",
"experimentalBypassFor": [ "experimentalBypassFor": [
......
export default async function Page() {
const data1 = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random',
{
headers: { traceparent: 'A' },
next: { revalidate: 50 },
}
).then((res) => res.text())
const data2 = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random',
{
headers: { traceparent: 'B' },
next: { revalidate: 50 },
}
).then((res) => res.text())
const echoedHeaders = await fetch(
'https://next-data-api-endpoint.vercel.app/api/echo-headers',
{
headers: { traceparent: 'C' },
next: { revalidate: 50 },
}
).then((res) => res.text())
return (
<>
<p id="data1">{data1}</p>
<p id="data2">{data2}</p>
<p id="echoedHeaders">{echoedHeaders}</p>
</>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment