Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove traceparent from cachekey should not remove traceparent from original object #64727

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/incremental-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export class IncrementalCache implements IncrementalCacheType {
const headers =
typeof (init.headers || {}).keys === 'function'
? Object.fromEntries(init.headers as Headers)
: Object.assign(init.headers || {}, {})
: Object.assign({}, init.headers)

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

Expand Down
16 changes: 16 additions & 0 deletions test/e2e/app-dir/app-static/app-static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
const res = await next.fetch('/too-many-cache-tags')
expect(res.status).toBe(200)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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>
</>
)
}