-
Notifications
You must be signed in to change notification settings - Fork 26k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure headers instance is serialized (#51047)
This makes sure we properly include headers in the cache key when a headers instance is used. x-ref: [slack thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1686234796532989)
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
test/e2e/app-dir/app-static/app/variable-revalidate/headers-instance/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fetchRetry = async (url, init) => { | ||
for (let i = 0; i < 5; i++) { | ||
try { | ||
return await fetch(url, init) | ||
} catch (err) { | ||
if (i === 4) { | ||
throw err | ||
} | ||
console.log(`Failed to fetch`, err, `retrying...`) | ||
} | ||
} | ||
} | ||
|
||
export default async function Page() { | ||
const data = await fetchRetry( | ||
'https://next-data-api-endpoint.vercel.app/api/random', | ||
{ | ||
headers: new Headers({ | ||
'x-hello': 'world', | ||
}), | ||
next: { | ||
revalidate: false, | ||
}, | ||
} | ||
).then((res) => res.text()) | ||
|
||
const data2 = await fetchRetry( | ||
'https://next-data-api-endpoint.vercel.app/api/random', | ||
{ | ||
headers: new Headers({ | ||
'x-hello': 'again', | ||
}), | ||
next: { | ||
revalidate: false, | ||
}, | ||
} | ||
).then((res) => res.text()) | ||
|
||
return ( | ||
<> | ||
<p id="page">/variable-revalidate/post-method-cached</p> | ||
<p id="page-data">{data}</p> | ||
<p id="page-data2">{data2}</p> | ||
</> | ||
) | ||
} |