Skip to content

Conversation

@drewsilcock
Copy link
Contributor

On Node v24+, the undici library used for HTTP has a Response class with a private element. Proxying the response therefore fails when calling clone() as the method returned by the proxy cannot access the private state element.

In the linked issue, I mention the MDN version of this fix using a simple function (...any) { ... } but I opted for the slightly more comprehensive one using Reflect.apply() and Object.defineProperties() as it ensures the returned function is identical to introspection (according to nodejs/undici#4290 (comment), anyway).

See: #15004.


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

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

I included a page in the test apps that reproduces the error (only on Node v24+, obviously). You can reproduce this error by visiting this test page with the fix from this PR reverted.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • 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

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

On Node v24+, the undici library used for HTTP has a Response class with
a private element. Proxying the response therefore fails when calling
clone() as the method returned by the proxy cannot access the private
state element.
By using Object.defineProperty(), we make the function identical to
introspection. Also, the linter didn't like the `...args`.
@changeset-bot
Copy link

changeset-bot bot commented Nov 28, 2025

🦋 Changeset detected

Latest commit: 73bb122

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 Patch

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

programming is magic, we just have to say the correct incantations, and you can't convince me otherwise 😆

thanks for fixing this! really glad I didn't have to track this down myself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was not fun to debug, I'm not going to lie 😄

Programs are basically spells, written in an arcane language decipherable only by those who study it closely, which we give breath to by running lightning through sand so yeah – if you showed this to someone from 1,000 years ago, you could not convince them that was it not magic

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github merged commit 977b8bd into sveltejs:main Nov 28, 2025
19 of 21 checks passed
@github-actions github-actions bot mentioned this pull request Nov 28, 2025
@drewsilcock drewsilcock deleted the bugfix/fix-undici-response-clone-typeerror branch December 2, 2025 10:49
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