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

Make prerendering +server.js responses play nicer with undici's Response #9566

Closed
Conduitry opened this issue Mar 30, 2023 · 0 comments · Fixed by #10030
Closed

Make prerendering +server.js responses play nicer with undici's Response #9566

Conduitry opened this issue Mar 30, 2023 · 0 comments · Fixed by #10030

Comments

@Conduitry
Copy link
Member

Describe the problem

If I have a +server.js endpoint that ends in a return fetch(...), this works fine in development, but if during building I attempt to prerender this endpoint's response, I get an error about headers being immutable from within undici. Presumably, SvelteKit is trying to change the response headers that it's getting from the +server.js function, and presumably the Response object that undici returns has had its headers frozen.

Describe the proposed solution

I think SvelteKit, at least when prerendering, should attempt to create a new Response object when it's adding its headers to the response.

Part of me has the potentially bad idea of running all undici responses through the code listed below in 'Alternatives considered'. Presumably someone, if they attempted to mutate such a Response in their handle hook after calling resolve would run into this same issue, even when not prerendering. (I've not actually tested this.) But perhaps at that point it's their responsibility to make sure they're handling this appropriately?

Alternatives considered

Right now, I'm running the responses through

new Response(response.body, {
		status: response.status,
		statusText: response.statusText,
		headers: new Headers(response.headers),
})

at the bottom of each relevant GET function, which works fine, but it took me a while to figure out what was going on and to arrive at this as a solution.

Importance

nice to have

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant