Skip to content

fix: render the nearest +error.svelte at the depth it occupies when an error is thrown during rendering - #16526

Merged
Rich-Harris merged 12 commits into
sveltejs:version-3from
Nic-Polumeyv:issue-16345-render-error-placement
Aug 13, 2026
Merged

Rich-Harris merged 12 commits into
sveltejs:version-3from
Nic-Polumeyv:issue-16345-render-error-placement

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

Fixes the error page placement half of #16345.

Since #16301, an error thrown while rendering is caught by the boundary at the depth that threw it, so the nearest +error.svelte renders inside every layout between its own directory and the throwing component. The same error thrown in load renders that component at its own depth with the intervening layouts unmounted. Before #16301 the generated root only armed a boundary at depths that own an error component (failed={errors[depth] ? failed : undefined}), which made render errors rethrow up to the owning depth. The unconditional boundary plus the nearest-ancestor findLast changed that without a changeset, first shipping in 3.0.0-next.8, the version #16345 was filed against. SvelteKit 2 places the same error at the owning depth.

The client and the server now build that array with one shared function instead of a copy each. Nearest-boundary selection (#14410, #15745) is unchanged, only where the selected error page renders.

set_nearest_error_page rebuilt the chain with no errors at all, so a render error inside a form error page fell back to the root one. It now passes the route's.

Conditional arming exposed a latent ordering problem in the #16296 reset path: navigate drains the resetters as soon as the new props are applied, before the flush, so a stale failed boundary re-renders its old content (which throws again) at a depth the new tree may no longer have. Unconditionally armed boundaries silently re-swallowed that throw on every teardown; with sparse arming it escaped to an ancestor boundary and rendered an error page instead of the new route. The drain now runs after settled(), matching the fork branch, which resets after state is applied. Boundaries at removed depths are simply unmounted by the flush; boundaries at surviving depths reset against a consistent tree.

The async test app's /server-error-boundary route already had exactly this shape, with the root error page silently rendering inside the section layout. The two existing tests now assert the layout is gone.

ghost commented Jul 26, 2026 •

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from ad36cd7:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/ad36cd7466e9d515fe4b883a7f9c4272f86e79b3

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16526

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

ghost commented Jul 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ad36cd7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

ghost commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

On version-3 the server and client don't just place render errors differently, they render different +error.svelte files for the same error. With a layout that throws and a sibling +error.svelte, pure SSR shows the root error page, SSR plus hydration shows the root page but the message becomes undefined, and client-side navigation renders the sibling error page inside the still-standing parent layout. Added a fixture and tests covering all three modes, failing on version-3 and passing here.

@ghost
ghost force-pushed the issue-16345-render-error-placement branch from c735389 to 9e20ac2 Compare July 28, 2026 19:41
@ghost
ghost marked this pull request as draft July 28, 2026 22:23
@ghost
ghost force-pushed the issue-16345-render-error-placement branch from 4b2e4a6 to c9cbc9d Compare July 28, 2026 23:41
@ghost
ghost marked this pull request as ready for review July 29, 2026 00:36
@ghost
ghost force-pushed the issue-16345-render-error-placement branch from 17d3064 to 0fa881f Compare July 29, 2026 21:46
@ghost
ghost force-pushed the issue-16345-render-error-placement branch from b1380cc to 459d4f4 Compare August 6, 2026 19:02
@ghost
ghost force-pushed the issue-16345-render-error-placement branch from 459d4f4 to ad3c9f6 Compare August 12, 2026 20:14

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@ghost
ghost merged commit 6e7d44d into sveltejs:version-3 Aug 13, 2026
@ghost ghost mentioned this pull request Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants