fix: replace Buffer.from with Uint8Array in toFormData - #11018
Merged
jasonsaayman merged 4 commits intoJun 25, 2026
Merged
Conversation
jasonsaayman
requested changes
Jun 18, 2026
mixelburg
commented
Jun 23, 2026
mixelburg
left a comment
Contributor
Author
There was a problem hiding this comment.
The changes requested by @jasonsaayman have been addressed in commit d701c4a (added typeof Buffer !== "undefined" guard). Requesting re-review.
…toFormData # Conflicts: # lib/helpers/toFormData.js
jasonsaayman
approved these changes
Jun 25, 2026
…toFormData # Conflicts: # PRE_RELEASE_CHANGELOG.md
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.
Fixes #10990
The only use of
Bufferin client-facing code is a singleBuffer.from(value)fallback intoFormData.js. Bundlers like Webpack (used by Next.js) detect this reference and pull in the fullbufferpolyfill into browser bundles.Replaced with
new Uint8Array(value)which is a native browser API accepted by bothFormDataand Node.js form-data. Also updated the error message on the Blob guard to reference ArrayBuffer/TypedArray instead of Buffer.All 596 unit tests pass.
Summary by cubic
Replaced direct
Buffer.fromintoFormDatawith a Node-only wrapper and browser-safeUint8Array/Blobhandling to avoid bundlerbufferpolyfills while keeping Node behavior intact.Description
lib/platform/node/classes/Buffer.jswithisBufferAvailable()andfrom().toFormDatato use the wrapper; browsers useBlob/Uint8Array../lib/platform/node/classes/Buffer.jsto./lib/helpers/null.jsfor browser and React Native inpackage.json.PRE_RELEASE_CHANGELOG.mdwith a FormData note (refs fix: replace Buffer.from with Uint8Array in toFormData #11018, closes Remove direct usage of Buffer #10990).bufferpolyfills in web builds while preserving Node conversion for non-specFormData.lib/helpers/toFormData.js.Docs
/docs/to notetoFormDataacceptsArrayBuffer/TypedArray in all environments; browsers produceBlob, and Node may useBufferfor non-specFormData. NoBufferrequirement in browsers.Testing
Bloband round-trips bytes.Bufferfor non-specFormData.Bufferstill applies. No additional tests needed.Semantic version impact
Written for commit 832c9f8. Summary will update on new commits.