mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
fix: remove value and writable properties from headers descriptor (#12552)
This commit is contained in:
parent
74ee2e45ec
commit
15f000c3e7
2 changed files with 15 additions and 3 deletions
5
.changeset/tame-hats-fold.md
Normal file
5
.changeset/tame-hats-fold.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixed an issue where modifying the `Request.headers` prototype during prerendering caused a build error. Removed conflicting value and writable properties from the `headers` descriptor to prevent `Invalid property descriptor` errors.
|
|
@ -70,9 +70,13 @@ export function createRequest({
|
|||
});
|
||||
|
||||
if (isPrerendered) {
|
||||
// Warn when accessing headers in prerendered pages
|
||||
const _headers = request.headers;
|
||||
const headersDesc = Object.getOwnPropertyDescriptor(request, 'headers') || {};
|
||||
// Warn when accessing headers in SSG mode
|
||||
let _headers = request.headers;
|
||||
|
||||
// We need to remove descriptor's value and writable properties because we're adding getters and setters.
|
||||
const { value, writable, ...headersDesc } =
|
||||
Object.getOwnPropertyDescriptor(request, 'headers') || {};
|
||||
|
||||
Object.defineProperty(request, 'headers', {
|
||||
...headersDesc,
|
||||
get() {
|
||||
|
@ -82,6 +86,9 @@ export function createRequest({
|
|||
);
|
||||
return _headers;
|
||||
},
|
||||
set(newHeaders: Headers) {
|
||||
_headers = newHeaders;
|
||||
},
|
||||
});
|
||||
} else if (clientAddress) {
|
||||
// clientAddress is stored to be read by RenderContext, only if the request is for a page that will be on-demand rendered
|
||||
|
|
Loading…
Reference in a new issue