Repository navigation
Description
Describe the bug
Under environment: 'jsdom', a Blob or File used as a request body arrives as the literal string undefined. Nothing throws, so a test uploading a file passes while sending nine bytes of ASCII instead of its content.
const blob = new Blob(['hello world'], { type: 'text/plain' })
const text = await new Request('http://x.test/', { method: 'POST', body: blob }).text()| environment | text |
|---|---|
| node | "hello world" |
| happy-dom | "hello world" |
| jsdom | "undefined" |
Same for a File inside FormData: the multipart part body is undefined, and fetch(URL.createObjectURL(blob)) returns undefined too.
Cause
makeCompatBlob in packages/vitest/src/integrations/env/jsdom.ts bridges jsdom's Blob to Node's fetch by reading a private field:
const buffer = (blob as any)[implSymbol]._buffer
return new NodeBlob_([buffer], { type: blob.type })jsdom 28.0.0 renamed that field to _bytes, so the read is undefined and new Blob([undefined]) stringifies it.
| jsdom | impl keys |
|---|---|
| 24.1.3 – 27.4.0 | _buffer,_globalObject,type |
| 28.1.0 – 29.1.1 | _globalObject,type,_bytes |
Vitest's own devDependency is jsdom: ^29.1.1, so the default combination is the broken one. The existing tests in test/unit/test/environments/jsdom.spec.ts use an empty new Blob() and only assert toBeInstanceOf, which is why CI stays green.
Reproduction
The snippet above, in any project with vitest@5.0.1 and jsdom@29, run once per environment. A single test file:
import { expect, test } from 'vitest'
test('blob bytes survive a Request body', async () => {
const blob = new Blob(['hello world'], { type: 'text/plain' })
const text = await new Request('http://x.test/', { method: 'POST', body: blob }).text()
expect(text).toBe('hello world')
})Passes with --environment=node and --environment=happy-dom, fails with --environment=jsdom.
System Info
vitest 5.0.1
jsdom 29.1.1
node 22.18.0
win32 x64
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines
- Read the docs
- Check that there isn't already an issue that reports the same bug
- Check that this is a concrete bug
- The provided reproduction is a minimal reproducible example of the bug
I used Claude to help investigate this. I ran the reproduction myself across the three environments and the six jsdom versions above.
Activity
hi-ogawa commentedon Sep 17, 2026
Where is this?
Greidal commentedon Sep 21, 2026
Hit this again on
vitest@4.1.11+jsdom@30.1.0, but through a different call path than the original report - constructing aRequestwith aFormDatabody containing aBlob/Fileentry, notURL.createObjectURL:I traced it to the same
createCompatUtils/makeCompatBlobinpackages/vitest/src/integrations/env/jsdom.tsthat #11295 touched -makeCompatFormDatacallsformData.forEach(), and for eachBlobentry callsmakeCompatBlob, which is the function #11295 patched.I think #11295's fix is incomplete, though, at least for this path. I patched a local install of
vitest@4.1.11with the exact merged diff (impl._bytes ?? impl._buffer) and re-ran the repro above - it still throws, just with'_bytes'instead of'_buffer'in the message now. Dug further and found why:On jsdom 30.1.0,
Object.getOwnPropertySymbols(Object.getOwnPropertyDescriptors(new window.Blob()))returns an empty array - a fresh jsdomBlobinstance no longer exposes its internal impl via an own Symbol property this way. SoimplSymbolisundefined, andblob[implSymbol](i.e.implin the patched code) is alsoundefinedregardless of which property name (_bufferor_bytes) is read off it afterward. The_bytes ?? _bufferfallback only helps in a case whereimplSymbolcorrectly resolves but the field name changed - it doesn't help here, sinceimplSymbolitself no longer resolves on 30.1.0.Minimal, framework-free repro confirming the symbol lookup itself is what's broken (
node repro.js, only needsjsdominstalled):Versions:
vitest@4.1.11,jsdom@30.1.0(30.0.1 is fine), Node24.19.0.Sorry for the noise across repos - I'd first misattributed this to
@mswjs/interceptors(mswjs/interceptors#841), then to jsdom itself (jsdom/jsdom#4361, which I'm closing now) before tracing it back here. Happy to open this as a fresh issue instead if that's preferred over reopening.harshit-d3v commentedon Sep 21, 2026
can reproduce this. it's not the
_bytesrename this time, jsdom 30.1.0 moved the impl into a private field (#implinlib/generated/idl/utils.js), so thegetOwnPropertySymbolsscan returns nothing andblob[implSymbol]is undefined.URL.createObjectURLbreaks the same way.only sync way to get the bytes now is jsdom's own
implForWrapper(jsdom/lib/generated/idl/utils.jsin 30.1,lib/jsdom/living/generated/utils.jsbefore). i have a fix that tries both paths and falls back to the symbol scan, passes on 29.1.1, 30.0.1 and 30.1.0 including your Request + FormData repro, plus a test that checks the bytes actually round-trip.@hi-ogawa #11300 touches the same function. want it added there or a separate PR once that lands?
fix(deps): hold jsdom at 30.0.1 for vitest's blob shim
fix(frontend): stub URL.createObjectURL unconditionally in graph PNG …