Skip to content

Throwing error inside of the root +layout.ts prohibits the page from loading when ssr = false #10201

Description

@oxisto

Describe the bug

If SSR is turned off and an error is thrown inside the "root" +layout.ts, the whole App does not load. Instead on the console you can see the error message as a rejected promise.

The intended behaviour would be to display the contents of the +error.svelte page - which seems to work fine if an error is thrown by any other +layout.ts file in any sub-directory except directly in src/routes/+layout.ts

Reproduction

Create a src/routes/+layout.ts:

import type { LayoutLoad } from './$types';
import { error } from '@sveltejs/kit';
export const ssr = false;
export const load = (async () => {
    throw error(400, "test")
}) satisfies LayoutLoad

I prepared a minimal repo as well: https://github.com/oxisto/layout-crash

Logs

Uncaught (in promise) HttpError {status: 400, body: {…}}body: {message: 'test'}status: 400[[Prototype]]: Objectconstructor: class HttpErrortoString: ƒ toString()[[Prototype]]: Object

System Info

System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M1
    Memory: 81.80 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.6.6 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 114.0.5735.133
    Safari: 16.4
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0
    @sveltejs/kit: ^1.20.4 => 1.20.4
    svelte: ^3.54.0 => 3.59.2
    vite: ^4.3.0 => 4.3.9

Severity

blocking all usage of SvelteKit

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions