Skip to content

fix: prerender errors during development - #16507

Merged
Rich-Harris merged 13 commits into
version-3from
prerender-dev-errors
Aug 10, 2026
Merged

fix: prerender errors during development#16507
Rich-Harris merged 13 commits into
version-3from
prerender-dev-errors

Conversation

@teemingc

@teemingc teemingc commented Jul 24, 2026

Copy link
Copy Markdown
Member

We've been tracking the current page's prerender option during SSR so we might as well enable some page prerendering behaviours during development to match what they'll get during the build.


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

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

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

pkg-svelte-dev Bot commented Jul 24, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 5de4b97:

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

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

@changeset-bot

changeset-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5de4b97

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

@svelte-docs-bot

Copy link
Copy Markdown

Comment thread packages/kit/src/runtime/server/page/load_data.js Outdated
Comment thread packages/kit/src/runtime/server/page/load_data.js Outdated
Comment thread packages/kit/src/runtime/server/page/render.js Outdated
Comment thread packages/kit/src/runtime/server/page/render.js Outdated
Comment thread packages/kit/src/runtime/server/page/render.js Outdated
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Comment thread packages/kit/src/runtime/server/page/render.js Outdated
Comment thread packages/kit/src/types/internal.d.ts Outdated
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Comment thread packages/kit/src/runtime/server/page/index.js Outdated
Comment thread packages/kit/src/runtime/server/page/index.js Outdated
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Comment thread packages/kit/src/runtime/server/page/index.js Outdated
@Nic-Polumeyv

Copy link
Copy Markdown
Contributor

state.prerendering || state.prerender_default === true appears nine times now, could be one helper:

/** @param {import('types').SSRState} state */
export function renders_prerendered_output(state) {
	return !!state.prerendering || (DEV && state.prerender_default === true);
}

The DEV guard is optional. Prerendered routes are filtered out of the server manifest at build time so these gates can't fire in production anyway, but that invariant lives in the adapter layer, and this makes the changeset's "during development" true by construction.

} else if (page_nodes) {
config = page_nodes.get_config() ?? config;
prerender = page_nodes.prerender();
prerender = state.prerender_default = page_nodes.prerender();

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.

is there any value in doing something like this immediately after this block, rather than adding prerender_default?

if (DEV && prerender) {
  state.prerendering = {
    dependencies: new Map(),
    remote_responses: new Map()
  };
}

It's a bit of a kludge but it would mean we didn't need to worry about forgetting the

|| state.prerender_default === true

part of

if (state.prerendering || state.prerender_default === true) {...}

Or does that not work for whatever reason?

@Nic-Polumeyv Nic-Polumeyv Jul 25, 2026

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.

I checked. event_state is created earlier in respond with prerendering: state.prerendering, so the request store would keep undefined unless that becomes a getter (or gets the same assignment). #16508 makes it a bit less cumbersome.

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.

That's true. But I think that itself is a problem — we have SSRState and EventState that overlap on prerender, and many functions that take both as arguments.

This was never intentional, just an artifact of organic software development — they should probably be unified into a single object. There are lots of adjacent tidy-ups that would be beneficial. But those would all be slightly disruptive changes that we should hold off on until the PR queue is emptier (specifically of things like #16464 and #15574), and as such I think we should hit pause on both this and #16508.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

is there any value in doing something like this immediately after this block, rather than adding prerender_default?

if (DEV && prerender) {
  state.prerendering = {
    dependencies: new Map(),
    remote_responses: new Map()
  };
}

Only downside I can think of is extra memory usage (if any?? maybe it's miniscule). Otherwise, would be nice to make the code simpler

@Nic-Polumeyv Nic-Polumeyv Aug 1, 2026

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.

With #16605 the desync I described is gone.

@teemingc teemingc added this to the 3.0 milestone Jul 31, 2026
Rich-Harris added a commit that referenced this pull request Aug 7, 2026
Part of #16519, doing the unification suggested in
#16507 (comment). One
request state object, forked for `event.fetch` sub-requests. This also
makes the `state.prerendering`-in-dev idea from #16507 workable, since
there's no second carrier to desync from anymore.

---------

Co-authored-by: Rich Harris <hello@rich-harris.dev>
@Rich-Harris
Rich-Harris merged commit 19c4478 into version-3 Aug 10, 2026
26 checks passed
@Rich-Harris
Rich-Harris deleted the prerender-dev-errors branch August 10, 2026 19:18
teemingc added a commit that referenced this pull request Aug 11, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-3, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-3` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-3`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @sveltejs/kit@3.0.0-next.19

### Major Changes

- breaking: move `defineParams` and associated types to
`@sveltejs/kit/params`
([#16716](#16716))

- breaking: run all errors through the `handleError` hook
([#16664](#16664))

- breaking: move `Page`, `ReadonlyURL` and `ReadonlyURLSearchParams`
from `@sveltejs/kit` to `$app/state`
([#16694](#16694))

- breaking: move `BeforeNavigate`, `OnNavigate`, `AfterNavigate`,
`Navigation`, `NavigationTarget`, `NavigationType`, `GotoOptions` and
the `Navigation*` variant types from `@sveltejs/kit` to
`$app/navigation` ([#16694](#16694))

- breaking: move `ActionResult` and `SubmitFunction` from
`@sveltejs/kit` to `$app/forms`
([#16694](#16694))

- breaking: remove `handleValidationError` and pass remote function
validation errors to `handleError` with `kind: 'validation'`
([#16672](#16672))

### Minor Changes

- feat: ignore files with + prefix if they contain test/spec/stories
([#16715](#16715))

### Patch Changes

- fix: rebuild the dev manifest when route files disappear during an
incremental update
([#16643](#16643))

- fix: externalize `@opentelemetry/api` to prevent bundler chunk
colocation between `instrumentation.server.js` and application code
([#16302](#16302))

- fix: surface prerender errors during development
([#16507](#16507))
## @sveltejs/adapter-node@6.0.0-next.9

### Patch Changes

- fix: externalize `@opentelemetry/api` to prevent bundler chunk
colocation between `instrumentation.server.js` and application code
([#16302](#16302))
- Updated dependencies
[[`04f9ab4`](04f9ab4),
[`1e198bd`](1e198bd),
[`813726d`](813726d),
[`a115a7b`](a115a7b),
[`031ac69`](031ac69),
[`dc7442c`](dc7442c),
[`19c4478`](19c4478),
[`dc7442c`](dc7442c),
[`dc7442c`](dc7442c),
[`0b3e2b3`](0b3e2b3)]:
  - @sveltejs/kit@3.0.0-next.19

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
teemingc pushed a commit that referenced this pull request Aug 11, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-3, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-3` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-3`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @sveltejs/kit@3.0.0-next.19

### Major Changes

- breaking: move `defineParams` and associated types to
`@sveltejs/kit/params`
([#16716](#16716))

- breaking: run all errors through the `handleError` hook
([#16664](#16664))

- breaking: move `Page`, `ReadonlyURL` and `ReadonlyURLSearchParams`
from `@sveltejs/kit` to `$app/state`
([#16694](#16694))

- breaking: move `BeforeNavigate`, `OnNavigate`, `AfterNavigate`,
`Navigation`, `NavigationTarget`, `NavigationType`, `GotoOptions` and
the `Navigation*` variant types from `@sveltejs/kit` to
`$app/navigation` ([#16694](#16694))

- breaking: move `ActionResult` and `SubmitFunction` from
`@sveltejs/kit` to `$app/forms`
([#16694](#16694))

- breaking: remove `handleValidationError` and pass remote function
validation errors to `handleError` with `kind: 'validation'`
([#16672](#16672))

### Minor Changes

- feat: ignore files with + prefix if they contain test/spec/stories
([#16715](#16715))

### Patch Changes

- fix: rebuild the dev manifest when route files disappear during an
incremental update
([#16643](#16643))

- fix: externalize `@opentelemetry/api` to prevent bundler chunk
colocation between `instrumentation.server.js` and application code
([#16302](#16302))

- fix: surface prerender errors during development
([#16507](#16507))

- fix: adjust error overload for optional `App.Error` parameters
([#16725](#16725))
## @sveltejs/adapter-node@6.0.0-next.9

### Patch Changes

- fix: externalize `@opentelemetry/api` to prevent bundler chunk
colocation between `instrumentation.server.js` and application code
([#16302](#16302))
- Updated dependencies
[[`04f9ab4`](04f9ab4),
[`1e198bd`](1e198bd),
[`813726d`](813726d),
[`a115a7b`](a115a7b),
[`031ac69`](031ac69),
[`dc7442c`](dc7442c),
[`19c4478`](19c4478),
[`dc7442c`](dc7442c),
[`dc7442c`](dc7442c),
[`0b3e2b3`](0b3e2b3),
[`c5d0ce2`](c5d0ce2)]:
  - @sveltejs/kit@3.0.0-next.19

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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