Skip to content

feat: better response logging - #16744

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

feat: better response logging#16744
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

pkg-svelte-dev Bot 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

changeset-bot Bot 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';

@teemingc teemingc 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

Comment thread packages/kit/src/runtime/server/internal.js Outdated
@svelte-docs-bot

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 <hello@rich-harris.dev>

@dummdidumm dummdidumm 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 Outdated
let progress_line = noop;

if (is_tty) {
let current = false;

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
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
@Rich-Harris
Rich-Harris merged commit 1611c61 into version-3 Aug 11, 2026
24 of 25 checks passed
@Rich-Harris
Rich-Harris deleted the better-logging branch August 11, 2026 20:54
Rich-Harris pushed a commit that referenced this pull request Aug 11, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-3, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-3` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-3`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @sveltejs/kit@3.0.0-next.20

### Major Changes

- breaking: move remote function types to `$app/server`
([#16740](#16740))

- breaking: remove `#lib` definition from `paths`; requires explicit
module extensions as a result
([#16736](#16736))

- breaking: move hooks-related types to `@sveltejs/kit/hooks`
([#16737](#16737))

- breaking: move env-related types to `@sveltejs/kit/env`
([#16739](#16739))

### Minor Changes

- feat: better response logging
([#16744](#16744))

### Patch Changes

- chore: bump `mrmime` to 2.0.1
([#16745](#16745))

- chore: bump `@sveltejs/acorn-typescript` to 1.0.12
([#16745](#16745))

- chore: bump `magic-string` to 1.1.0
([#16745](#16745))

- chore: bump `devalue` to 5.9.0
([#16745](#16745))

- chore: bump `cookie` to 2.0.1
([#16745](#16745))

- chore: bump `acorn` to 8.18.0
([#16745](#16745))

- fix: avoid infinite loop when building with `--watch` flag
([#16632](#16632))
## @sveltejs/adapter-cloudflare@8.0.0-next.6

### Patch Changes

- chore: bump `@cloudflare/worker-types` to 5.20260809.1
([#16745](#16745))
- Updated dependencies
[[`1742811`](1742811),
[`1611c61`](1611c61),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`13e7b18`](13e7b18),
[`529346d`](529346d),
[`b361b81`](b361b81),
[`81d6319`](81d6319),
[`b361b81`](b361b81),
[`69a5bdf`](69a5bdf)]:
  - @sveltejs/kit@3.0.0-next.20
## @sveltejs/adapter-netlify@7.0.0-next.8

### Patch Changes

- chore: bump `rolldown` to 1.2.3
([#16745](#16745))
- Updated dependencies
[[`1742811`](1742811),
[`1611c61`](1611c61),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`13e7b18`](13e7b18),
[`529346d`](529346d),
[`b361b81`](b361b81),
[`81d6319`](81d6319),
[`b361b81`](b361b81),
[`69a5bdf`](69a5bdf)]:
  - @sveltejs/kit@3.0.0-next.20
## @sveltejs/adapter-node@6.0.0-next.10

### Patch Changes

- chore: bump `rolldown` to 1.2.3
([#16745](#16745))
- Updated dependencies
[[`1742811`](1742811),
[`1611c61`](1611c61),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`b361b81`](b361b81),
[`13e7b18`](13e7b18),
[`529346d`](529346d),
[`b361b81`](b361b81),
[`81d6319`](81d6319),
[`b361b81`](b361b81),
[`69a5bdf`](69a5bdf)]:
  - @sveltejs/kit@3.0.0-next.20
## @sveltejs/enhanced-img@1.0.0-next.5

### Patch Changes

- chore: bump `magic-string` to 1.1.0
([#16745](#16745))

- chore: bump `zimmerframe` to 1.1.4
([#16745](#16745))
## @sveltejs/package@3.0.0-next.6

### Patch Changes

- chore: bump `svelte2tsx` to 0.7.59
([#16745](#16745))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Rich-Harris added a commit that referenced this pull request Aug 12, 2026
follow-up to #16744 — turns out we need this or `stdout` can buffer
updates for long enough that progress appears stalled.

before:



https://github.com/user-attachments/assets/25019619-5d60-42e8-aa8c-bc051fba64ca

after:



https://github.com/user-attachments/assets/094891d1-4028-4033-8c2e-56ab3dbcf394



---

### Please don't delete this checklist! Before submitting the PR, please
make sure you do the following:

- [x] 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
- [x] This message body should clearly illustrate what problems it
solves.
- [ ] Ideally, include a test that fails without this PR but passes with
it.

### Tests

- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint` and `pnpm check`

### Changesets

- [x] 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

- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs
without this option may be closed.

---------

Co-authored-by: Nic Polumeyv <nicolas.polum@outlook.com>
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