Skip to content

breaking: remove experimental.handleRenderingErrors flag - #16265

Merged
Rich-Harris merged 12 commits into
version-3from
remove-rendering-error-flag
Jul 8, 2026
Merged

Rich-Harris merged 12 commits into
version-3from
remove-rendering-error-flag

Conversation

@Rich-Harris

Copy link
Copy Markdown
Member

Removes the flag, as this is the default behaviour in SvelteKit 3


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

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@pkg-svelte-dev

ghost commented Jul 7, 2026 •

Copy link
Copy Markdown

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

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

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

@changeset-bot

ghost commented Jul 7, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fa432ff

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 Major

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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Additional Suggestion:

Docs still instruct users to enable the removed experimental.handleRenderingErrors flag, which now throws a hard config-validation error.

Fix on Vercel

@svelte-docs-bot

ghost commented Jul 7, 2026

Copy link
Copy Markdown

@Rich-Harris

ghost commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

gah — this is tricky. transformError is an async function, because handleError might be async. but if transformError returns a Promise then Svelte throws an error if experimental.async isn't enabled. I think this means we need to

  1. keep this under an experimental flag for now, which would really suck (we badly need this feature)
  2. disallow async handleError client hooks unless experimental.async is enabled

vercel[bot] and others added 3 commits July 7, 2026 22:49
… the error status because the reworked `transformError` no longer reassigns the local `status` variable

This commit fixes the issue reported at packages/kit/src/runtime/server/page/render.js:205

## Bug

In `packages/kit/src/runtime/server/page/render.js`, `status` is a mutable destructured parameter of `render_response` (line 59). It is consumed in two places:

- Hydration payload (line 512): `if (status !== 200 && !error) hydrate.push(...)`
- The final HTTP response (line 670): `text(transformed, { status, headers })`

The **base** implementation's `transformError` callback reassigned this closure-scoped variable when an error was caught:

```js
props.page.status = status = transformed.status;
```

The **reworked** callback (commit `2718a1d`) only updated `props.page.status` in both the sync and async branches, dropping the `status = ...` assignment:

```js
props.page.status = error.status; // local `status` never updated
```

## Trigger / failure mode

A page whose `load` succeeds (so `render_response` is invoked with `status: 200`) but whose Svelte component **throws during rendering** and is caught by an error boundary. `transformError` runs, produces e.g. a 500 error object, sets `props.page.status = 500`, but the local `status` stays `200`. The response is then built with `text(transformed, { status: 200 })`, so the client receives an HTTP `200 OK` containing the error page instead of the correct `500`. This is a behavioral regression from the base implementation.

## Fix

Restore the local reassignment in both the sync and async branches:

```js
props.page.status = status = error.status;
```

This keeps the HTTP status code (and the hydration `status` field) in sync with the error status, matching the previous behavior. I left `props.error` unchanged, as the boundary renders the error via the `failed` snippet using the `transformError` return value rather than the root `error` prop.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <[email protected]>
@Rich-Harris

ghost commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

I went with 'don't wrap sync handleError hooks in an async function', which means that the await_invalid error doesn't happen if your hook is synchronous. If you do hit the error, it's a little cryptic, but I'm honestly not sure how best to address that other than docs

Rich Harris added 2 commits July 7, 2026 20:28

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.

One question otherwise LGTM. Update: Nevermind, I should've read the comments before reviewing. But I've gotta say it's somewhat of a big ask - "hey you have an async handleError on the server, you gotta add async: true now whether you want to or not".

@Rich-Harris

ghost commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

But I've gotta say it's somewhat of a big ask

Existing async hooks will continue to work for the errors they work for today (i.e. load errors etc). For render errors it'll now fail somewhat gracefully, by returning a generic error and printing a 'please enable the flag' warning

vercel[bot] and others added 2 commits July 8, 2026 18:17
…ch can cause an unhandled promise rejection that crashes the server

This commit fixes the issue reported at packages/kit/src/runtime/server/utils.js:122

## Bug

In `handle_error_and_jsonify` (`packages/kit/src/runtime/server/utils.js`), when the user's `handleError` hook returns a `Promise` but the app is **not** running with `compilerOptions.experimental.async` enabled and the error occurs during rendering (`!__SVELTEKIT_SUPPORTS_ASYNC__ && state.is_in_render`), the function warns and returns a generic error object:

```js
if (result instanceof Promise) {
	if (!__SVELTEKIT_SUPPORTS_ASYNC__ && state.is_in_render) {
		console.warn(...);
		return { status, message: 'Internal Error' };  // <-- `result` promise discarded
	}
	...
}
```

The `result` promise is **discarded without being awaited or given a `.catch()` handler**.

`with_request_store` (`packages/kit/src/exports/internal/server/event.js`) only wraps the call in `try/finally` — **not** `try/catch` — so it passes the promise straight through without attaching any rejection handler:

```js
export function with_request_store(store, fn) {
	try {
		sync_store = store;
		return als ? als.run(store, fn) : fn();
	} finally {
		if (!IN_WEBCONTAINER) sync_store = null;
	}
}
```

Nothing else along the path handles it.

## Concrete trigger

1.  User defines an **async** `handleError` hook that can reject (e.g. an `await`ed call to an external logging/Sentry service that throws).
2.  `compilerOptions.experimental.async` is **not** enabled — exactly the misconfiguration this branch warns about.
3.  A rendering error occurs → `handle_error_and_jsonify` is reached with `state.is_in_render === true` and the hook returns a promise.
4.  The warn branch returns the generic object and drops `result`.
5.  When `result` later rejects, there is no handler → **unhandled promise rejection**. Under Node.js v15+ default behavior (`--unhandled-rejections=throw`), this can terminate the server process.

## Fix

Attach a no-op `.catch(() => {})` to the discarded promise before returning, preventing the unhandled rejection:

```js
// we're discarding the result, but we still need to prevent an unhandled
// rejection if the user's async `handleError` hook rejects
result.catch(() => {});

return { status, message: 'Internal Error' };
```

This matches the codebase's existing convention for intentionally-ignored promises (`event.js:14`, `core/postbuild/queue.js:20`, `app/server/remote/requested.js:263`).


Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <[email protected]>
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.

3 participants