You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
handleFetch hook receive empty event object after 2.31.0 sveltekit upgrade.
For ssr http calls handleFetch act as an http interceptor and we add auth details via event object . But after the upgrade the ssr calls started to throw 401 as auth details were empty in the event object as event object itself was coming empty.
CORS error: No 'Access-Control-Allow-Origin' header is present on the requested resource
at universal_fetch (...)
I should have mentioned that I have a Traefik Reverse Proxy on a dev.example.com domain, that proxies the request to my local machine running vite dev.
I'm also getting a CORS error: No 'Access-Control-Allow-Origin' header is present on the requested resource error when I try to fetch JSON from a REST API.
I, again, updated past SvelteKit 2.31.0 and ran into the same issue.
However I found a fix. But I really don't know if this is the way it is supposed to be...
// hooks.server.ts// We have to handle the x-forwarded-proto header, because we are deployed behind a reverse proxy// Otherwise CORS errors with sveltekit server to backend will occur, especially with using the `fetch` API in load functionexportconsthandle: Handle=async({ event, resolve })=>{constproto=event.request.headers.get("x-forwarded-proto")if(proto){event.url=newURL(event.url.href.replace(/^http:/,`${proto}:`))}returnresolve(event)}exportconsthandleFetch: HandleFetch=async({ request, event, fetch })=>{consturl=newURL(request.url)constproto=event.request.headers.get("x-forwarded-proto")// Derive public origin (same logic as handleForwardedProto)constpublicOrigin=proto ? event.url.origin.replace(/^http:/,`${proto}:`) : event.url.origin// Inject Origin header for cross-origin requestsif(url.origin!==publicOrigin&&!request.headers.get("origin")){constheaders=newHeaders(request.headers)headers.set("origin",publicOrigin)request=newRequest(request,{ headers })}returnfetch(request)}
My network setup is the following:
Frontend: https://example.com → Traefik Reverse Proxy → SvelteKit/Vite dev server
Backend: https://api.example.com → Traefik Reverse Proxy → Rust backend server
Request for comment
🙏🏽 I'd highly appreciate at least a comment pointing out a possible mistake or misunderstanding...
The issue with troubleshooting this is that there are too many variables to consider. The very least we would need is to know the exact way you’ve setup your reverse proxy, sveltekit project and the how the request was sent. So we need a reproduction repository and reproduction steps
https://github.com/Nic-Polumeyv/sveltekit-handlefetch-event-probe runs the same app against 2.30.1, 2.31.0 and 2.70.1. On 2.30.1, a handle hook that reassigns event.url from x-forwarded-proto propagates everywhere. From 2.31.0 on, handleFetch sees the stale url, and a reassigned event.locals arrives empty, which is the empty event reported here.
The cause is #13899, shipped in 2.31.0. handle receives a spread copy of the event (traced_event = { ...event, tracing } in respond.js), while event.fetch was created earlier and closed over the original. Reassignments inside handle land on the copy. handleFetch, the origin header kit injects into server fetches, and cookie forwarding all read the original; the CORS check in universal load reads the copy. In the proxy setup no backend header can pass: kit sends Origin: http://… and when the backend echoes exactly that in Access-Control-Allow-Origin, the check still fails because it compares against the mutated url. Property writes like event.locals.user = x still propagate because the copy is shallow. @timephy's workaround works because kit only injects origin when the header is absent, so setting it in handleFetch wins.
@golaughlin's case is different: fetching a cross-origin API that returns no Access-Control-Allow-Origin fails on every version, that check predates this (#7454).
Rich suggested making tracing getter-based during #13899 review so the same event object could flow throughout (#13899 (comment)), which would fix this class. The alternative is declaring property reassignment in handle unsupported, as #11902 (comment) already does for the underlying x-forwarded-proto pattern, though 2.30.x supported it in practice.
You can't just reassign event.url. That needs to happen before SvelteKit sees the app. I guess we need to mark that property readonly in the types.
I'm also getting a CORS error: No 'Access-Control-Allow-Origin' header is present on the requested resource error when I try to fetch JSON from a REST API.
It sounds like whatever's serving from localhost:8000 isn't adding an Access-Control-Allow-Origin header? Seems unrelated to the issue at hand.
VSCode also throws a Property 'children' does not exist on type '{}' problem.
That's because you're importing ../$types instead of ./$types. If you're using VS Code with the Svelte extension you don't need to import any types, they will be injected for you.
Am inclined to close this issue — the OP is vague and there's no repro, and the other two things don't sound like SvelteKit bugs.
Activity
Conduitry commentedon Dec 8, 2025
Please provide a complete and minimal reproduction, not just a code snippet referring to other parts of your codebase that aren't included.
timephy commentedon Dec 17, 2025
When updating past
2.31.0I get this error withvite devSSR using the providedfetchto request some data.I run this in
hooks.server.ts:I set this up a long time ago.
Removing it does not solve the issue.
timephy commentedon Dec 18, 2025
I should have mentioned that I have a Traefik Reverse Proxy on a
dev.example.comdomain, that proxies the request to my local machine runningvite dev.golaughlin commentedon Dec 25, 2025
I'm also getting a
CORS error: No 'Access-Control-Allow-Origin' header is present on the requested resourceerror when I try to fetch JSON from a REST API../routes/children/+page.ts
./routes/children/+page.svelte
VSCode also throws a
Property 'children' does not exist on type '{}'problem.timephy commentedon Jan 7, 2026
As this (in my case) seems to depend on individual-domain-hosting... How can I help recreate this for you? @Conduitry
I would love to help push this into the right direction to get this fixed. It's preventing me from updating atm..
timephy commentedon Feb 14, 2026
I, again, updated past SvelteKit 2.31.0 and ran into the same issue.
However I found a fix. But I really don't know if this is the way it is supposed to be...
My network setup is the following:
Frontend:
https://example.com→ Traefik Reverse Proxy → SvelteKit/Vite dev serverBackend:
https://api.example.com→ Traefik Reverse Proxy → Rust backend serverRequest for comment
🙏🏽 I'd highly appreciate at least a comment pointing out a possible mistake or misunderstanding...
teemingc commentedon Feb 14, 2026
The issue with troubleshooting this is that there are too many variables to consider. The very least we would need is to know the exact way you’ve setup your reverse proxy, sveltekit project and the how the request was sent. So we need a reproduction repository and reproduction steps
Nic-Polumeyv commentedon Jul 26, 2026
https://github.com/Nic-Polumeyv/sveltekit-handlefetch-event-probe runs the same app against 2.30.1, 2.31.0 and 2.70.1. On 2.30.1, a handle hook that reassigns
event.urlfromx-forwarded-protopropagates everywhere. From 2.31.0 on,handleFetchsees the stale url, and a reassignedevent.localsarrives empty, which is the empty event reported here.The cause is #13899, shipped in 2.31.0.
handlereceives a spread copy of the event (traced_event = { ...event, tracing }in respond.js), whileevent.fetchwas created earlier and closed over the original. Reassignments inside handle land on the copy.handleFetch, theoriginheader kit injects into server fetches, and cookie forwarding all read the original; the CORS check in universal load reads the copy. In the proxy setup no backend header can pass: kit sendsOrigin: http://…and when the backend echoes exactly that inAccess-Control-Allow-Origin, the check still fails because it compares against the mutated url. Property writes likeevent.locals.user = xstill propagate because the copy is shallow. @timephy's workaround works because kit only injectsoriginwhen the header is absent, so setting it in handleFetch wins.@golaughlin's case is different: fetching a cross-origin API that returns no
Access-Control-Allow-Originfails on every version, that check predates this (#7454).Rich suggested making tracing getter-based during #13899 review so the same event object could flow throughout (#13899 (comment)), which would fix this class. The alternative is declaring property reassignment in handle unsupported, as #11902 (comment) already does for the underlying x-forwarded-proto pattern, though 2.30.x supported it in practice.
Rich-Harris commentedon Aug 5, 2026
You can't just reassign
event.url. That needs to happen before SvelteKit sees the app. I guess we need to mark that propertyreadonlyin the types.It sounds like whatever's serving from
localhost:8000isn't adding anAccess-Control-Allow-Originheader? Seems unrelated to the issue at hand.That's because you're importing
../$typesinstead of./$types. If you're using VS Code with the Svelte extension you don't need to import any types, they will be injected for you.Am inclined to close this issue — the OP is vague and there's no repro, and the other two things don't sound like SvelteKit bugs.
fix: mark `RequestEvent` properties as `readonly` (#16661)