Skip to content

Content negotiation fails with fetch from __layout #5732

@CaptainCodeman

Description

@CaptainCodeman

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 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

System Info

System:
    OS: macOS 12.4
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 29.02 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.14.0 - /usr/local/bin/node
    npm: 8.3.1 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 102.1.39.111
    Chrome: 103.0.5060.134
    Chrome Canary: 106.0.5204.0
    Edge: 103.0.1264.71
    Firefox: 102.0.1
    Safari: 15.5
    Safari Technology Preview: 16.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64 
    @sveltejs/kit: next => 1.0.0-next.396 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions