Skip to content

Render +error.svelte whenever possible #13646

@theetrain

Description

@theetrain

Describe the bug

From the docs: https://svelte.dev/docs/kit/routing#error

+error.svelte is not used when an error occurs inside handle or a +server.js request handler.

Not sure if this is a bug or feature request, but I'm thinking +error.svelte should be rendered whenever possible, and not only when performing client-side navigation. The current behaviour is inconsistent (see reproduction below).

Reproduction

https://www.sveltelab.dev/g4cglz64hfgy3vm

  1. Load REPL, observe 500 error rendered by error.html
  2. Navigate to /test manually in the preview pane
  3. Click on 'home' link
  4. Observer /src/routes/+error.svelte being rendered instead of error.html

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.3.1 
    @sveltejs/kit: ^2.5.27 => 2.20.2 
    @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.3 
    svelte: ^5 => 5.25.3 
    vite: ^6.0.0 => 6.2.3

Severity

annoyance

Additional Information

I could not find duplicate issues, and I'm not sure if this is a bug or feature request. If implemented, it would certainly be a breaking change and a potential candidate for SvelteKit 3.

Here's a somewhat related problem presented on Discord: Documentation/help for custom error page for top-level hooks.server.ts error in which someone is attempting to use reroute to maintain the URL while capturing and throwing errors in handle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions