Skip to content

chore: gate the server runtime behind configure - #17008

Open
Nic-Polumeyv wants to merge 6 commits into
server-bootfrom
prerender-configure-once
Open

chore: gate the server runtime behind configure#17008
Nic-Polumeyv wants to merge 6 commits into
server-bootfrom
prerender-configure-once

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Kit's postbuild forks, dev and preview each imported server/internal.js, called configure, and only then imported server/index.js, because the runtime statically imports the generated env module, which evaluates the user's src/env config, which may read building. Nothing enforced that order beyond a comment in each caller, and prerender.js set the same state three times along the way.

Following #17008 (comment), server/index.js now exports configure, which sets the state and returns the runtime as import('./instance.js'), so the runtime, and with it the env config, is unreachable without going through it. create_server and the Server shim stay in the entry, so adapters are untouched. With nothing able to run before configure, options no longer needs a setter, set_env is a static binding on the instance, and the state setting moves out of the string template in write_server.js into the entry, leaving the generated module with options and get_hooks. server/internal.js is no longer emitted.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Sep 2, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 7e03e39:

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

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

@changeset-bot

changeset-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7e03e39

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: QUIET

Plan: Advanced

Run ID: 7d21e5c7-389b-47e0-a86d-200520ecd0ce

📥 Commits

Reviewing files that changed from the base of the PR and between 3dbec6d and 7e03e39.

📒 Files selected for processing (2)
  • packages/kit/src/runtime/server/index.js
  • packages/kit/src/runtime/server/instance.js
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • sveltejs/vite-plugin-svelte (manual)
  • vitejs/vite (manual)
  • sveltejs/svelte (manual)

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The server runtime now exposes configure, which returns a server instance with init and respond methods. Runtime setup and request handling moved into server/instance.js. Build, development, preview, fallback, and prerender paths now use the configured instance. Error handling moved to respond_with_error.js. Types, templates, Vite inputs, and test mocks were updated.

Priority: ⬇️ Low — Defer this server-runtime restructuring because it changes initialization across build, development, preview, and prerender flows without supplied external urgency.

Merge Risk: ⚪ Minimal · up to 7e03e

The configured server-instance transition preserves request handling responsibilities without identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required chore: prefix and accurately summarises the main change: gating the server runtime behind configure.
Backward Compatibility Impact Disclosure ✅ Passed No breaking public interface is introduced under this check. The public Server, ServerInitOptions, request, and response declarations are unchanged. The Server class remains available and is onl…

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/kit/src/runtime/server/index.js

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/kit/src/runtime/server/instance.js

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@svelte-docs-bot

Copy link
Copy Markdown

await configure({ building: true, manifest, env });

/** @type {import('types').ServerModule} */
const { init, respond } = await import(pathToFileURL(`${server_root}/server/index.js`).href);

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github Sep 2, 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.

This makes me wonder... can we invert this and make the "this stuff must happen before this other stuff" API explicit? Instead of having /server/internal.js, could we have just /server/index.js, which exports configure, and configure returns init and respond?

	/** @type {import('types').ServerInternalModule} */
	const { configure } = await import(pathToFileURL(`${server_root}/server/index.js`).href);
	const { init, respond } = await configure({ building: true, manifest, env });

Internally configure would basically just be returning import(pathToFileURL(./do-not-import-this-yourself.js).href), so what's "actually happening" is basically the same, but it would guarantee callers in these several places would have to call configure before importing the stuff that depends on what configure does.

@Nic-Polumeyv Nic-Polumeyv changed the title chore: configure the prerender server once chore: gate the server runtime behind configure Sep 2, 2026
Comment thread packages/kit/src/core/postbuild/prerender.js
@Nic-Polumeyv
Nic-Polumeyv force-pushed the prerender-configure-once branch from 66bbaeb to e1e2090 Compare September 3, 2026 15:21
@teemingc
teemingc force-pushed the prerender-configure-once branch from e1e2090 to 3dbec6d Compare September 8, 2026 12:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: QUIET

Plan: Advanced

Run ID: 79aa5acf-1c2c-44b1-949a-769045503406

📥 Commits

Reviewing files that changed from the base of the PR and between 66bbaeb and 3dbec6d.

📒 Files selected for processing (4)
  • packages/kit/src/exports/vite/build/index.js
  • packages/kit/src/runtime/server/index.js
  • packages/kit/src/runtime/server/page/render.js
  • packages/kit/src/types/internal.d.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • sveltejs/vite-plugin-svelte (manual)
  • vitejs/vite (manual)
  • sveltejs/svelte (manual)

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Comment on lines +27 to +30
const instance = await import('./instance.js');
if (env) instance.set_env(env);

return instance;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

printf '%s\n' '--- changed file ---'
sed -n '1,110p' packages/kit/src/runtime/server/index.js
printf '%s\n' '--- configure and callers ---'
rg -n -A35 -B8 'configure|create_server|new Server|class Server' packages/kit/src packages/kit/test packages/kit/tests 2>/dev/null | head -240
printf '%s\n' '--- instance state references ---'
rg -n -A4 -B4 'set_env|manifest|read|env' packages/kit/src/runtime/server/instance.js packages/kit/src/runtime/server 2>/dev/null | head -260

Repository: sveltejs/kit

Length of output: 39648


🤖 get_repo_knowledge executed:

get_repo_knowledge sveltejs/kit /tmp/coderabbit-repo-knowledge/sveltejs-kit-ab1bcef7/conventions

Length of output: 897


🏁 Script executed:

printf '%s\n' '--- module-level state definitions ---'
sed -n '1,180p' packages/kit/src/runtime/server/internal.js
printf '%s\n' '--- instance initialisation and request path ---'
sed -n '1,190p' packages/kit/src/runtime/server/instance.js
printf '%s\n' '--- configure/create_server consumers ---'
rg -n --glob '!packages/kit/src/runtime/server/index.js' '\b(configure|create_server)\b|from .*[\\/]server[\\/]index' packages/kit packages 2>/dev/null | head -180
printf '%s\n' '--- generated server instance implementation ---'
rg -n -A45 -B15 'generateServerInstance' packages/kit/src packages/kit/test 2>/dev/null | head -220

Repository: sveltejs/kit

Length of output: 35337


🏁 Script executed:

printf '%s\n' '--- server API and generation documentation ---'
rg -n -i -A12 -B8 'generateServerInstance|create_server|server instance|multiple.*server|server.*multiple|ServerInitOptions' documentation packages/kit/src packages/kit/types packages/*/README.md 2>/dev/null | head -260
printf '%s\n' '--- all generated-instance call sites and adapter output ---'
rg -n -A12 -B8 'generateServerInstance\(|export const server = create_server|server\.init\(' packages/adapter-* packages/kit/src packages/kit/test 2>/dev/null | head -320

Repository: sveltejs/kit

Length of output: 44154


Document or enforce the one-server-per-module-graph contract. configure() updates module-level manifest and read_implementation state, then returns cached ./instance.js. If two create_server() instances share a module graph, initialising the second can make the first use the second server's configuration. Add an interleaved two-manifest regression test or isolate state per server.

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