fix: don't invoke handleError for server-handled errors during preload - #16474
fix: don't invoke handleError for server-handled errors during preload#16474ondraulehla wants to merge 1 commit into
Conversation
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
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/f555c519f298dca35ab226a8fbc3f3f94de71c9aOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: f555c51 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
I already see a few issues. v3 doesn't have this bug since #12579, and this would be a minimal fix on main. With v3 release being prepared I'd close this rather than take maintainer review time. |
|
You're right, thanks for checking. #12579 rethrows the server error node as an |
closes #16456
When a preloaded route's server
loadthrowserror(404), the clienthandleErrorhook runs with the raw server error node andstatus: 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 asbefore. The new test preloads a route whose server load throws
error(404)viapreloadData()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) andpnpm lintpass;pnpm checkfails on upstream main itself (pre-existing, unrelated)Changesets
@sveltejs/kitpatch,fix:prefix)Edits