fix(jsdom): fix Request with Blob body on jsdom 28+ - #11295
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
🟢 Approval recommended
The fix and regression tests address the reported issue with no unresolved review comments.
Pull request overview
Fixes Blob and File request bodies under jsdom 28+ by supporting its renamed internal byte field.
Changes:
- Supports both
_bytesand legacy_buffer. - Adds regression tests for Blob and multipart File bodies.
File summaries
| File | Description |
|---|---|
test/unit/test/environments/jsdom.spec.ts |
Adds request-body regression tests. |
packages/vitest/src/integrations/env/jsdom.ts |
Adds compatibility for both jsdom byte-field names. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
hi-ogawa
left a comment
There was a problem hiding this comment.
Can you check CI fali?
|
Pushed a fix. undici 7 on Node 24 resolves |
|
iirc there was something tricky about Node 24 |
|
Yes, that's it. undici 7 dropped the node:buffer imports (nodejs/undici#4362, Node 24.6+), so Pushed the other half too. The parser builds each part with |
|
Aren't the two issues independent? Should we split PR? |
|
You're right, they're independent: #11294 is the jsdom 28 |
|
split pls |
jsdom 28 renamed the private `_buffer` field to `_bytes`, so `makeCompatBlob` read `undefined` and every Blob or File used as a request body arrived as the string "undefined".
067347e to
f2ca33e
Compare
|
The only red job is the #11251 browser-mode mock flake again ( |
Where is this? You seem to suggest there's already a test case to expand. |
|
it's the const data = new Blob()
form.set(key, data)
const retrievedBlob = form.get(key)
expect(retrievedBlob).toBeInstanceOf(Blob)that one uses an empty blob and only checks the type, so it never noticed the bytes were gone. the test i added sends a real blob as a request body and reads it back, thats the case that was broken. |
|
should |
|
right, that was more of a side note than something this PR needs. making i mentioned it in the issue just to explain why the regression wasn't caught before. i can drop that line if it reads as if the old test should change. |
|
What about the coverage of |
|
the break only shows when the blob is passed to Node's fetch/Request, which is the path |
Request with Blob body
Request with Blob bodyRequest with Blob body since jsdom 28
Request with Blob body since jsdom 28 Request with Blob body on jsdom 28+
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [vitest](https://vitest.dev) ([source](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest)) | [`5.0.1` → `5.0.2`](https://renovatebot.com/diffs/npm/vitest/5.0.1/5.0.2) |  |  | --- ### Release Notes <details> <summary>vitest-dev/vitest (vitest)</summary> ### [`v5.0.2`](https://github.com/vitest-dev/vitest/releases/tag/v5.0.2) [Compare Source](vitest-dev/vitest@v5.0.1...v5.0.2) ##### 🐞 Bug Fixes - Bind `process` in case global is overwritten - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11343](vitest-dev/vitest#11343) [<samp>(0b792)</samp>](vitest-dev/vitest@0b79231ad) - **detect-async-leaks**: - Ignore `process.stdio` handles - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11333](vitest-dev/vitest#11333) [<samp>(0fd6b)</samp>](vitest-dev/vitest@0fd6b9790) - **expect**: - Fix `toMatchObject` with asymmetric matchers - by [@​ShreeBohara](https://github.com/ShreeBohara), **Claude Opus 5**, [@​hi-ogawa](https://github.com/hi-ogawa), **Hiroshi Ogawa** and **Codex (GPT-5)** in [#​11100](vitest-dev/vitest#11100) [<samp>(42523)</samp>](vitest-dev/vitest@42523289e) - **jsdom**: - Fix `Request` with `Blob` body on jsdom 28+ - by [@​harshit-d3v](https://github.com/harshit-d3v) in [#​11295](vitest-dev/vitest#11295) [<samp>(d1c3e)</samp>](vitest-dev/vitest@d1c3ecc93) - **reporter**: - `agent` to respect `--silent` - by [@​Raj4478](https://github.com/Raj4478) and [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11271](vitest-dev/vitest#11271) [<samp>(5b95e)</samp>](vitest-dev/vitest@5b95efb6d) - **reporters**: - Handle concurrent `createReport` calls - by [@​7rulnik](https://github.com/7rulnik) in [#​11278](vitest-dev/vitest#11278) [<samp>(e8e55)</samp>](vitest-dev/vitest@e8e556ff7) - `hanging-process` to use ESM entrypoint - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11316](vitest-dev/vitest#11316) [<samp>(4e91e)</samp>](vitest-dev/vitest@4e91e5668) - **spy**: - Fix stack overflow when spying `Set.prototype.add` - by [@​fengmk2](https://github.com/fengmk2) in [#​11299](vitest-dev/vitest#11299) [<samp>(a0a93)</samp>](vitest-dev/vitest@a0a939653) - **ui**: - Persist authentication cookie beyond current browser session - by [@​hi-ogawa](https://github.com/hi-ogawa), **Hiroshi Ogawa** and **OpenCode (gpt-5.6-sol)** in [#​11066](vitest-dev/vitest#11066) [<samp>(f8819)</samp>](vitest-dev/vitest@f88195e16) ##### [View changes on GitHub](vitest-dev/vitest@v5.0.1...v5.0.2) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMTUuMTMiLCJ1cGRhdGVkSW5WZXIiOiI0NC4xMTUuMTMiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbXX0=-->
Description
Under
environment: 'jsdom', aBlobused as a request body arrives as the stringundefined.makeCompatBlobreads jsdom's private_bufferfield, which jsdom 28 renamed to_bytes. Reads whichever exists so both halves of the*peer range keep working.Adds a test that fails without the change: a
Blobused as aRequestbody. The existingsupports Blobtest uses an empty blob and only checkstoBeInstanceOf, so it never saw the content go missing.The related Node 24
File/FormDatabreakage (#9135) is a separate issue with a different cause (undici 7 readingFilefrom the global) and will be a follow-up PR.Resolves #11294
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.I used Claude to help find and fix this. I reproduced it myself and reviewed the change.