Skip to content

feat: simplify custom entrypoint stuff - #16560

Merged
teemingc merged 15 commits into
feat-server-entrypointfrom
feat-server-entrypoint-alt
Jul 29, 2026
Merged

feat: simplify custom entrypoint stuff#16560
teemingc merged 15 commits into
feat-server-entrypointfrom
feat-server-entrypoint-alt

Conversation

@Rich-Harris

Copy link
Copy Markdown
Member

continuation of #16464. This isn't complete — the types need a little finessing (in the handler, it probably doesn't make sense for server to have an init method, and the second argument to server.respond should be optional and only include platform), and getClientAddress doesn't currently work. But you get the idea

@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 29, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 9ea4977:

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

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

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9ea4977

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

@svelte-docs-bot

Copy link
Copy Markdown

@vercel vercel Bot 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 Suggestions:

  1. Prerender/fallback import the custom handler from the stale server/index.js path, which no longer exists after the build output was renamed to server/handler.js
  1. Fallback page generation imports the custom handler from the non-existent server/index.js after the build entry key was renamed to handler

Fix on Vercel

Comment thread packages/kit/src/exports/vite/dev/index.js Outdated
Comment thread packages/kit/src/runtime/server/default-handler.js Outdated
@teemingc

Copy link
Copy Markdown
Member

/autofix

@vercel vercel Bot 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:

vite.config.js and tsconfig.json reference the renamed adapter-handler.js file, which no longer exists (renamed to .ts), breaking the custom-handler pipeline.

Fix on Vercel

teemingc and others added 6 commits July 30, 2026 00:53
… clientAddress during prerendering` for normal requests because the dev SSR handler wires up a prerender-style throwing stub instead of returning the request's socket address.

This commit fixes the issue reported at packages/kit/src/exports/vite/dev/index.js:599

## Bug

Commit `8f22bf0` ("pass getClientAddress directly") reworked how `getClientAddress` is provided to the SSR handler. In the **preview** server this was done correctly — the per-request `respond` wrapper now injects:

```js
getClientAddress: () => {
	const { remoteAddress } = req.socket;
	if (remoteAddress) return remoteAddress;
	throw new Error('Could not determine clientAddress');
}
```

But in the **dev** server (`packages/kit/src/exports/vite/dev/index.js`), the same refactor pasted the *prerender* implementation into the request-handling wrapper:

```js
getClientAddress: () => {
	throw new Error('Cannot read clientAddress during prerendering');
},
```

This wrapper is the one used for real dev requests (it's created per request inside the Vite middleware, where `req` is in scope). So any app that calls `event.getClientAddress()` in a load function, endpoint, or hook now throws `Cannot read clientAddress during prerendering` under `vite dev` — a nonsensical error for a live request, and a regression from the previous behavior where the real socket address was returned.

### Concrete trigger

Run `vite dev` and hit any route whose `load`/endpoint/hook calls `event.getClientAddress()`. Instead of the client IP, the request fails with `Cannot read clientAddress during prerendering`.

## Fix

Replace the throwing stub in the dev handler's `respond` wrapper with the same socket-based implementation used by the preview server. `req` is already in closure scope because the `Server` and its wrapper are constructed per request inside the middleware.

The preview server (`packages/kit/src/exports/vite/preview/index.js`) already provides `getClientAddress` correctly after `8f22bf0`, so no change is needed there.


Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <hello@rich-harris.dev>
@teemingc
teemingc merged commit cf92069 into feat-server-entrypoint Jul 29, 2026
21 checks passed
@teemingc
teemingc deleted the feat-server-entrypoint-alt branch July 29, 2026 17:28
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