Server-side fetch request should have headers
See original GitHub issueFetch call made from the server should have the same headers, as the one made from the client.
<!-- index.svelte -->
<script context="module">
export async function load({ fetch }) {
const { headers } = await fetch('/content.json').then(res => res.json())
return {
props: { headers }
}
};
</script>
// content.json.ts
export const get = (request) => ({
body: {
headers: request.headers // <- headers: {} if requested during SSR, but populated otherwise
}
});
In the above case the request.headers
are empty ({}
) if requested during SSR, but populated when requested from the client on navigation or if requested directly.
The expected behavior is that in both cases the headers are populated and requests look the same.
envinfo:
npmPackages:
@sveltejs/adapter-node: next => 1.0.0-next.10
@sveltejs/kit: next => 1.0.0-next.60
svelte: ^3.29.0 => 3.35.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:12
- Comments:20 (9 by maintainers)
Top Results From Across the Web
Using the Fetch API - MDN Web Docs
Since headers can be sent in requests and received in responses, and have various limitations about what information can and should be mutable, ......
Read more >Data Fetching: getServerSideProps - Next.js
Pages using getServerSideProps will be server side rendered at request time and only be cached if cache-control headers are configured. If you do...
Read more >reactjs - 'ReferenceError: Headers is not defined' when using ...
I'm setting up a new application in React and I want it to be server side rendered. Unfortunately I'm not able to use...
Read more >Different ways to fetch data in Next.js (server-side) and when ...
When building an application powered by Next.js it's probable that you'll need to fetch data from either a file, an internal API route...
Read more >Making HTTP Requests in Node.js with node-fetch
A web application often needs to communicate with web servers to get various resources. You might need to fetch data from or post...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fetch
inonMount
is a reasonable workaround, yeah. We’ll get this fixed soon though, it’s a priorityWithout this feature I have a tree of components that need to wait for a follow up request before they can be rendered. The follow up request fetches the auth token from an endpoint. It slows the performance of the site down a lot, and also increases the complexity of my code.