feat: better response logging - #16744
Merged
Merged
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/d84cda9deace7d7dd267b04d2418bd60bafa3118Open in |
🦋 Changeset detectedLatest commit: d84cda9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
teemingc
reviewed
Aug 11, 2026
| 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'; |
… `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
approved these changes
Aug 11, 2026
dummdidumm
left a comment
Member
There was a problem hiding this comment.
comment request, else LGTM
| let progress_line = noop; | ||
|
|
||
| if (is_tty) { | ||
| let current = false; |
Member
There was a problem hiding this comment.
Comment explaining what this is doing and why would be good
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
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>
6 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)