Skip to content

Commit

Permalink
fix: removing traceparent from cachekey should not remove traceparent…
Browse files Browse the repository at this point in the history
… from request
  • Loading branch information
Jeffrey committed Apr 19, 2024
1 parent 134a59d commit 16f10ca
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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
33 changes: 33 additions & 0 deletions test/e2e/app-dir/app-static/app/strip-header-traceparent/page.tsx
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>
</>
)
}

0 comments on commit 16f10ca

Please sign in to comment.