fix(browser): Send gzipped request body as ArrayBuffer#3172
fix(browser): Send gzipped request body as ArrayBuffer#3172dustinbyrne merged 3 commits intomainfrom
Conversation
In WebKit, calling `fetch` with a `Blob` in the body results in an empty request. Using an ArrayBuffer allows the bytes to be written directly to the request body buffer, while Blobs require a seperate lookup in a blob registry. Presumably this step is failing (seems like a bug?).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| contentType: CONTENT_TYPE_PLAIN, | ||
| body: blob, | ||
| estimatedSize: blob.size, | ||
| body: gzipData.buffer.slice(gzipData.byteOffset, gzipData.byteOffset + gzipData.byteLength) as ArrayBuffer, |
There was a problem hiding this comment.
Tests in request.test.ts at lines 403 and 508 expect Blob but will now receive ArrayBuffer. Update tests to:
- Line 403:
expect(mockedXHR.send.mock.calls[0][0]).toBeInstanceOf(ArrayBuffer) - Line 508:
expect.any(ArrayBuffer)instead ofexpect.any(Blob)
And update how the test reads the data since FileReader won't work with ArrayBuffer.
|
Size Change: +351 B (+0.01%) Total Size: 6.69 MB
ℹ️ View Unchanged
|
867fdee to
a46f154
Compare
CI is still unhappy |
pauldambra
left a comment
There was a problem hiding this comment.
a change scarily deep in the internals 🙈
narrowing down the calls it looks less scary in terms of volume
the robot assures me ArrayBuffer is well-supported
I didn't run this locally but assume you did and playwright is happy anyway
pauldambra
left a comment
There was a problem hiding this comment.
vercel failure seems unrelated
> playground-nextjs@0.1.0 build /vercel/path0/playground/nextjs
> next build --no-lint
⚠ Linting is disabled.
▲ Next.js 15.5.7
Checking validity of types ...
Creating an optimized production build ...
Failed to compile.
./pages/index.tsx
Module not found: Can't resolve 'posthog-js/lib/src/customizations'
https://nextjs.org/docs/messages/module-not-found
> Build failed because of webpack errors
ELIFECYCLE Command failed with exit code 1.
Error: Command "pnpm build" exited with 1
Problem
Playwright integration tests are failing quite often on Safari.
After some debugging, I discovered that some event ingestion requests were returning 400 responses, stating the body was empty.
As it turns out, WebKit sends an empty request body via
fetchwhen the body contains aBlob. I was able to confirm this behavior in a separate minimal reproduction. This likely affects other Safari users as well.Integration tests on Safari were only passing if the events could be sent before remote config was received, enabling compression (and thus sending blobs on fetch). The Playwright test mocked both
/array/<token>/configand/flagsas a source of remote config but not/array/<token>/config.js, which we've recently switched to. When we switched over, the integration tests began hitting the real service, getting a full remote config, and enabling compression.Changes
We now send an ArrayBuffer instead of a Blob.
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file