Skip to content

fix: don't invoke handleError for server-handled errors during preload#16474

Open
ondraulehla wants to merge 1 commit into
sveltejs:mainfrom
ondraulehla:fix/preload-handle-error
Open

fix: don't invoke handleError for server-handled errors during preload#16474
ondraulehla wants to merge 1 commit into
sveltejs:mainfrom
ondraulehla:fix/preload-handle-error

Conversation

@ondraulehla

Copy link
Copy Markdown

closes #16456

When a preloaded route's server load throws error(404), the client
handleError hook runs with the raw server error node and status: 500.
On normal navigation the branch loader skips the client hook for errors
already handled on the server, but the preload path returns before that
guard is reached. As the issue describes, integrations that filter out
4xx by status (like Sentry) then report ordinary server 404s as client
500s, just because a link was hovered instead of clicked.

I moved the error and status computation in front of the preload return,
so preloads go through the same guard as normal navigation. The
updated.check() reload logic stays out of the preload path, same as
before. The new test preloads a route whose server load throws
error(404) via preloadData() and asserts the hook is not invoked —
it fails without the fix and passes with it, in both dev and build modes.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

Tests

  • pnpm test (basics suite) and pnpm lint pass; pnpm check fails on upstream main itself (pre-existing, unrelated)

Changesets

  • Changeset included (@sveltejs/kit patch, fix: prefix)

Edits

  • 'Allow edits from maintainers' is checked

When a preloaded route's server load throws error(), the branch loader's
preload path returned before the server_data_nodes guard, so the client
handleError hook ran with the raw server error node and status 500.
Error-reporting integrations that filter 4xx by status (e.g. Sentry)
therefore reported ordinary server-rendered 404s as client 500s whenever
a link was hovered instead of clicked.

Compute the error and status through the same guard as normal navigation
before the preload return, so server-handled errors skip the client hook
on the preload path too.

Fixes sveltejs#16456
@pkg-svelte-dev

Copy link
Copy Markdown

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

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

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

Note

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

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f555c51

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

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.

1 participant