Skip to content

hanszoons/sveltekit-rendering-error-boundary-repro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SvelteKit handleRenderingErrors boundary doesn't reset on client navigation

Minimal reproduction for a bug in SvelteKit's experimental kit.experimental.handleRenderingErrors.

An error() thrown in a remote query that is await-ed inside a component is a render error. With handleRenderingErrors: true SvelteKit catches it in the per-route <svelte:boundary> and shows the nearest +error.svelte — correct.

But on a subsequent client-side navigation the failed boundary is never reset(), so the +error.svelte stays mounted on a now-valid page until a hard reload. The reactive page store does update (page.status goes back to 200), giving an inconsistent UI.

Run

pnpm install
pnpm dev

Steps

  1. Open / → "Home".
  2. Click thing/missing (404) → "Error: 404" / "missing" not found (correct).
  3. Click thing/exists (ok)BUG: URL is /thing/exists but the page still shows "Error: 200" instead of "Thing exists".
  4. A hard reload restores "Thing exists".

Expected: step 3 shows "Thing exists" (boundary resets on navigation). Actual: the +error.svelte stays until a full reload.

Root cause

.svelte-kit/generated/root.svelte wraps each route layer in a <svelte:boundary>. A failed Svelte 5 boundary stays failed until reset() is called. The client router (@sveltejs/kit/src/runtime/client/client.js) only clears its own rendering_error tracking var and calls root.$set(...) on each client navigation — it never calls reset() on the boundary, nor is the boundary {#key}-ed on the route:

rendering_error = null; // TODO this can break with forks, rethink for SvelteKit 3 where we can assume Svelte 5
root.$set(navigation_result.props);

The first load is fine because it goes through initialize(), which creates the root fresh.

About

Minimal repro: SvelteKit handleRenderingErrors boundary stays mounted on client navigation

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages