Skip to content

feat: better response logging - #16744

Merged
Rich-Harris merged 11 commits into
version-3from
better-logging
Aug 11, 2026
Merged

Rich-Harris merged 11 commits into
version-3from
better-logging

Conversation

@Rich-Harris

Copy link
Copy Markdown
Member

small quality of life improvement — response logging is a bit quieter, especially when prerendering lots of stuff (as we do on svelte.dev for example)

@pkg-svelte-dev

ghost commented Aug 11, 2026 •

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from d84cda9:

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

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

@changeset-bot

ghost commented Aug 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d84cda9

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 Minor

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

import process from 'node:process';
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { clearLine, moveCursor } from 'node:readline';

ghost Aug 11, 2026 •

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.

TIL there's a node:readline

@svelte-docs-bot

ghost commented Aug 11, 2026

Copy link
Copy Markdown

vercel[bot] and others added 2 commits August 11, 2026 18:53
… `internal.js` can crash non-Node runtimes (Cloudflare Workers, Vercel Edge, Deno) at module load, since this module is bundled into the server shipped to all adapter targets.

This commit fixes the issue reported at packages/kit/src/runtime/server/internal.js:3

## The bug

`log_response` was moved into `packages/kit/src/runtime/server/internal.js`, which is **runtime code**, not build/dev-time code:

- `internal.js` is aliased to `__sveltekit/server` (`packages/kit/src/exports/vite/index.js:441-443`).
- Its exports (including `log_response`) are re-exported by the generated server entry (`packages/kit/src/core/sync/write_server.js:28,81`).
- Therefore `internal.js` is bundled into the server that ships to **all** adapter targets, including non-Node edge runtimes.

The new code added a top-level static import:

```js
import { styleText } from 'node:util';
```

This directly contradicts the deliberate pattern used by the sibling module it re-exports from, `packages/kit/src/runtime/server/sourcemaps.js`, which fetches Node builtins via `globalThis.process?.getBuiltinModule?.('node:...')` with the comment:

> using `getBuiltinModule` rather than `import` makes this safe to run in non-Node-compatible environments

## Failure mode

`log_response` is only ever invoked from Node-only build/dev contexts:
- `packages/kit/src/exports/vite/dev/index.js` (dev server)
- `packages/kit/src/core/postbuild/prerender.js` (prerender)

It is **never** called from the production request handler. But because the function (and its `node:util` import) live in a runtime module that is bundled for every adapter, a static `import ... from 'node:util'` risks surviving into the deployed server bundle. On a runtime that does not provide `node:util` (or lacks the relatively new `styleText`), resolving that import at module load throws and crashes the worker — even though the imported symbol is never used at request time. Whether tree-shaking removes it is bundler/adapter-dependent and not guaranteed, so relying on it is fragile.

## The fix

Replaced the static import with the established `getBuiltinModule` pattern, with a graceful fallback that returns the plain text when `styleText` is unavailable:

```js
// using `getBuiltinModule` rather than `import` makes this safe to run in non-Node-compatible environments
const styleText =
	globalThis.process?.getBuiltinModule?.('node:util')?.styleText ??
	((_format, text) => text);
```

In Node (engines require `>=22.17`, where `styleText` is present) behavior is unchanged; in non-Node runtimes module load no longer depends on a static `node:util` import, and `log_response` (if ever called) degrades to plain, uncolored output. Type check (`tsc --noEmit`) reports no errors for the file.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <[email protected]>

ghost left a comment

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.

comment request, else LGTM

Comment thread playgrounds/basic/vite.config.js Resolved
let progress_line = noop;

if (is_tty) {
let current = false;

ghost Aug 11, 2026

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.

Comment explaining what this is doing and why would be good

Rich Harris and others added 2 commits August 11, 2026 16:53
@Rich-Harris
Rich-Harris merged commit 1611c61 into version-3 Aug 11, 2026
@Rich-Harris
Rich-Harris deleted the better-logging branch August 11, 2026 20:54
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