Skip to content

fix: prerender errors during development#16507

Open
teemingc wants to merge 10 commits into
version-3from
prerender-dev-errors
Open

fix: prerender errors during development#16507
teemingc wants to merge 10 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 8ef31c6:

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

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: 8ef31c6

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.

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