Skip to content

chore: gate the server runtime behind configure - #17008

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

chore: gate the server runtime behind configure#17008
Nic-Polumeyv wants to merge 5 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 e1e2090:

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

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: e1e2090

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 Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: 6043c09e-4cd6-474f-be31-62bbe928c9f9

📥 Commits

Reviewing files that changed from the base of the PR and between 4f69920 and 66bbaeb.

📒 Files selected for processing (20)
  • packages/kit/src/core/postbuild/analyse.js
  • packages/kit/src/core/postbuild/fallback.js
  • packages/kit/src/core/postbuild/prerender.js
  • packages/kit/src/core/sync/write_server.js
  • packages/kit/src/exports/vite/build/index.js
  • packages/kit/src/exports/vite/dev/index.js
  • packages/kit/src/exports/vite/preview/index.js
  • packages/kit/src/runtime/server/errors.js
  • packages/kit/src/runtime/server/index.js
  • packages/kit/src/runtime/server/instance.js
  • packages/kit/src/runtime/server/internal.js
  • packages/kit/src/runtime/server/page/index.js
  • packages/kit/src/runtime/server/page/render.js
  • packages/kit/src/runtime/server/page/respond_with_error.js
  • packages/kit/src/runtime/server/respond.js
  • packages/kit/src/types/ambient-private.d.ts
  • packages/kit/src/types/internal.d.ts
  • packages/kit/test/apps/basics/vite.config.js
  • packages/kit/test/mocks/generated-server.js
  • packages/kit/vitest.kit.config.js
💤 Files with no reviewable changes (1)
  • packages/kit/src/exports/vite/build/index.js

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


Important

Approval pending

CodeRabbit has no unresolved comments, but it has not reviewed the latest commit.

Use the checkbox below to review the latest commit. CodeRabbit will approve the changes if it finds no blocking issues.

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The server runtime now exposes configure, which returns a server instance with init and respond methods. Runtime setup, request handling, tracing, hooks, transport, environment setup, and webcontainer serialisation moved into server/instance.js. Build, development, preview, fallback, and prerender paths now use the configured instance. Error-page and fatal-error handling moved to respond_with_error.js. Generated server types, templates, Vite inputs, and test mocks were updated.

Sequence Diagram(s)

sequenceDiagram
  participant EntryPoint
  participant ServerModule
  participant ServerInstance
  participant ResponseHandler
  EntryPoint->>ServerModule: configure(server options)
  ServerModule->>ServerInstance: create configured instance
  EntryPoint->>ServerInstance: init()
  EntryPoint->>ServerInstance: respond(request, options)
  ServerInstance->>ResponseHandler: generate response
  ResponseHandler-->>ServerInstance: Response
  ServerInstance-->>EntryPoint: Response
Loading

Suggested reviewers: rich-harris, ottomated

Merge Risk: ⚪ Minimal · up to 66bba

The change gates server runtime initialization behind configure to enforce environment setup ordering; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains how the PR gates the server runtime behind configure and describes the related state and generated-module changes.
Title check ✅ Passed The title is concise and accurately summarises the main change: gating the server runtime behind configure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch prerender-configure-once

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
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.

2 participants