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
The normal content negotiation ability to be served html or json data based on the http accept header seems to break if the request comes from __layout.svelte. Instead of the expected content, it returns a 404 response.
Request root with accept: application/json header and expected data is returned
Request root with browser and error is produced (see log below - status from fetch is 404)
Changing url fetched in __layout to /__data.json OR renaming index.svelte "fixes" it (of course, you likely want a home page so the latter isn't really a fix, just thought it may help identify the cause).
Using __data.json works so it's not a show-stopper, but in case someone else comes across it this will hopefully be findable.
Logs
Unexpected token N in JSON at position 0
SyntaxError: Unexpected token N in JSON at position 0
at JSON.parse (<anonymous>)
at Proxy.<anonymous> (file:///Users/simon/dev/open-source/sveltekit-shadow-layout/.svelte-kit/runtime/server/index.js:2559:21)
at async load (__layout.svelte:9:14)
at async load_node (file:///Users/simon/dev/open-source/sveltekit-shadow-layout/.svelte-kit/runtime/server/index.js:2585:22)
at async respond$1 (file:///Users/simon/dev/open-source/sveltekit-shadow-layout/.svelte-kit/runtime/server/index.js:2986:15)
at async resolve (file:///Users/simon/dev/open-source/sveltekit-shadow-layout/.svelte-kit/runtime/server/index.js:3456:11)
at async respond (file:///Users/simon/dev/open-source/sveltekit-shadow-layout/.svelte-kit/runtime/server/index.js:3392:20)
at async file:///Users/simon/dev/open-source/sveltekit-shadow-layout/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/vite.js:1555:22
The point is it shouldn't fail, it should work. It works when calling the same endpoint from other places, or by calling the different (unnormalized? non-canonical?) form (__data.json). Just not calling '/' from __layout.svelte
The reason JSON parse fails is because the response is a 404, which is what's wrong. It should get the JSON data. The exact same code inside index.svelte works, so it's a "surprise".
Describe the bug
The normal content negotiation ability to be served html or json data based on the http accept header seems to break if the request comes from __layout.svelte. Instead of the expected content, it returns a 404 response.
Reproduction
example repo
Request root with
accept: application/json
header and expected data is returnedRequest root with browser and error is produced (see log below - status from fetch is 404)
Changing url fetched in __layout to
/__data.json
OR renamingindex.svelte
"fixes" it (of course, you likely want a home page so the latter isn't really a fix, just thought it may help identify the cause).Using __data.json works so it's not a show-stopper, but in case someone else comes across it this will hopefully be findable.
Logs
System Info
Severity
annoyance
Additional Information
The scenario is having the root endpoint be the data for the site, in a SaaS setup where the sites are served based on host name.
The text was updated successfully, but these errors were encountered: