-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(core) - Prevent Buffer from being auto-polyfilled
- Loading branch information
Showing
2 changed files
with
10 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@urql/core': patch | ||
--- | ||
|
||
Prevent `Buffer` from being polyfilled by an automatic detection in Webpack. Instead of referencing the `Buffer` global we now simply check the constructor name. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,12 @@ const boundaryHeaderRe = /boundary="?([^=";]+)"?/i; | |
|
||
type ChunkData = { done: false; value: Buffer | Uint8Array } | { done: true }; | ||
|
||
// NOTE: We're avoiding referencing the `Buffer` global here to prevent | ||
// auto-polyfilling in Webpack | ||
const toString = (input: Buffer | ArrayBuffer): string => | ||
typeof Buffer !== 'undefined' && Buffer.isBuffer(input) | ||
? input.toString() | ||
: decoder!.decode(input); | ||
input.constructor.name === 'Buffer' | ||
? (input as Buffer).toString() | ||
: decoder!.decode(input as ArrayBuffer); | ||
|
||
// DERIVATIVE: Copyright (c) 2021 Marais Rossouw <[email protected]> | ||
// See: https://github.com/maraisr/meros/blob/219fe95/src/browser.ts | ||
|