Skip to content

Commit

Permalink
fix: do not replace headers on fetch requests with error state (#13341)
Browse files Browse the repository at this point in the history
Fixes #13340
  • Loading branch information
aureleoules authored Jan 21, 2025
1 parent 891429e commit b764298
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-scissors-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: avoid overwriting headers for sub-requests made while loading the error page
10 changes: 5 additions & 5 deletions packages/kit/src/runtime/server/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ export async function respond(request, options, manifest, state) {
}

if (state.error && event.isSubRequest) {
return await fetch(request, {
headers: {
'x-sveltekit-error': 'true'
}
});
// avoid overwriting the headers. This could be a same origin fetch request
// to an external service from the root layout while rendering an error page
const headers = new Headers(request.headers);
headers.set('x-sveltekit-error', 'true');
return await fetch(request, { headers });
}

if (state.error) {
Expand Down

0 comments on commit b764298

Please sign in to comment.