Skip to content

missing prerendered route with load function returns internal error instead of 404 #8751

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

Closed
eltigerchino opened this issue Jan 27, 2023 · 1 comment · Fixed by #11025
Closed
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Milestone

Comments

@eltigerchino
Copy link
Member

eltigerchino commented Jan 27, 2023

Describe the bug

A client-side navigation to a route that:

  • has a dynamic parameter.
  • has prerender = true.
  • has a page load function.
  • does not have a root layout server load function.

incorrectly returns internal error 500 instead of a 404 when navigating to a non-existent dynamic parameter.

This is because the response for the /__data.json of the non-existent route is returned as HTML instead of JSON.
Then, the client-side router tries to parse the HTML response as JSON, throwing an error, and causing a 500 failed page render.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-sswrw5?file=src/routes/+layout.svelte

  1. Enter npm run build && npm run preview in the terminal
  2. Open the preview website and enter 2 into the text input.
  3. Click on the link below the text input.

Expected

Error page returns 404

Actual

Error page returns 500

Logs

Server logs

Error: Not found: /test/2
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2410:18)
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2277:34)
    at #options.hooks.handle (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2454:59)
    at respond (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2275:43)
Error: Not found: /test/_app/immutable/assets/_layout-8454f68e.css
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2410:18)
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2277:34)
    at #options.hooks.handle (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2454:59)
    at respond (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2275:43)
Error: Not found: /test/_app/immutable/start-eeb7962b.js
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2410:18)
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2277:34)
    at #options.hooks.handle (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2454:59)
    at respond (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2275:43)
Error: Not found: /test/_app/immutable/chunks/index-3f4e8c83.js
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2410:18)
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2277:34)
    at #options.hooks.handle (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2454:59)
    at respond (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2275:43)
Error: Not found: /test/_app/immutable/chunks/singletons-6817b8d2.js
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2410:18)
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2277:34)
    at #options.hooks.handle (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2454:59)
    at respond (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2275:43)
Error: Not found: /test/_app/immutable/chunks/index-ef589868.js
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2410:18)
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2277:34)
    at #options.hooks.handle (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2454:59)
    at respond (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2275:43)
Error: Not found: /test/_app/immutable/components/pages/_layout.svelte-fb9359d7.js
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2410:18)
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2277:34)
    at #options.hooks.handle (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2454:59)
    at respond (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2275:43)
Error: Not found: /test/_app/immutable/components/error.svelte-6ead235a.js
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2410:18)
    at resolve (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2277:34)
    at #options.hooks.handle (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2454:59)
    at respond (file://file:///home/projects/sveltejs-kit-template-default-sswrw5/.svelte-kit/output/server/index.js:2275:43)

Browser console

start-eeb7962b.js:1          GET https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/2/__data.json?x-sveltekit-invalidated=_1 404 (Not Found)
Qe @ start-eeb7962b.js:1
qe @ start-eeb7962b.js:1
je @ start-eeb7962b.js:1
le @ start-eeb7962b.js:1
(anonymous) @ start-eeb7962b.js:1
start-eeb7962b.js:1 SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
handleError @ start-eeb7962b.js:1
te @ start-eeb7962b.js:1
qe @ start-eeb7962b.js:1
await in qe (async)
je @ start-eeb7962b.js:1
le @ start-eeb7962b.js:1
(anonymous) @ start-eeb7962b.js:1
/test/_app/immutable/assets/_layout-8454f68e.css:1          GET https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/_app/immutable/assets/_layout-8454f68e.css net::ERR_ABORTED 404 (Not Found)
/test/_app/immutable/start-eeb7962b.js:1          GET https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/_app/immutable/start-eeb7962b.js net::ERR_ABORTED 404 (Not Found)
/test/_app/immutable/chunks/index-3f4e8c83.js:1          GET https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/_app/immutable/chunks/index-3f4e8c83.js net::ERR_ABORTED 404 (Not Found)
/test/_app/immutable/chunks/singletons-6817b8d2.js:1          GET https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/_app/immutable/chunks/singletons-6817b8d2.js net::ERR_ABORTED 404 (Not Found)
/test/_app/immutable/chunks/index-ef589868.js:1          GET https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/_app/immutable/chunks/index-ef589868.js net::ERR_ABORTED 404 (Not Found)
/test/_app/immutable/components/pages/_layout.svelte-fb9359d7.js:1          GET https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/_app/immutable/components/pages/_layout.svelte-fb9359d7.js net::ERR_ABORTED 404 (Not Found)
/test/_app/immutable/components/error.svelte-6ead235a.js:1          GET https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/_app/immutable/components/error.svelte-6ead235a.js net::ERR_ABORTED 404 (Not Found)
/test/2:1 The resource https://sveltejskittemplatedefaultsswrw5-v0ya--4173.local-credentialless.webcontainer.io/test/_app/immutable/assets/_layout-8454f68e.css was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.2 
    @sveltejs/kit: ^1.2.10 => 1.3.1 
    svelte: ^3.54.0 => 3.55.1 
    vite: ^4.0.0 => 4.0.4

Severity

serious, but I can work around it

Additional Information

No response

@benmccann benmccann added bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. labels Jan 27, 2023
@benmccann benmccann added this to the soon milestone Jan 27, 2023
@eltigerchino eltigerchino changed the title prerendered route with load function returns internal error dynamic prerendered route with load function returns internal error Feb 4, 2023
@eltigerchino eltigerchino changed the title dynamic prerendered route with load function returns internal error missing route with load function returns internal error instead of 404 Feb 4, 2023
@eltigerchino eltigerchino changed the title missing route with load function returns internal error instead of 404 missing prerendered route with load function returns internal error instead of 404 Feb 4, 2023
@korywka
Copy link

korywka commented Apr 8, 2023

This bug blocks upgrade from 1.3.0 if you are using cloudflare adapter 🥹

dummdidumm added a commit that referenced this issue Nov 14, 2023
fixes #8751

This PR handles the edge case where loading the data of a non-existent prerendered dynamic route returns a 404 HTML page instead of JSON data. No test because our /basics test app has a root server layout load function, which causes it to do a native navigation instead, returning a 404 SSR response. The error only occurs when there is no root server layout load.

---------

Co-authored-by: Simon H <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants