Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

(core) - Prevent Buffer from being auto-polyfilled (#2027)

Changed files
+10 -3
.changeset
packages
core
src
internal
+5
.changeset/lucky-pens-end.md
···
···
+
---
+
'@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.
+5 -3
packages/core/src/internal/fetchSource.ts
···
type ChunkData = { done: false; value: Buffer | Uint8Array } | { done: true };
const toString = (input: Buffer | ArrayBuffer): string =>
-
typeof Buffer !== 'undefined' && Buffer.isBuffer(input)
-
? input.toString()
-
: decoder!.decode(input);
// DERIVATIVE: Copyright (c) 2021 Marais Rossouw <hi@marais.io>
// See: https://github.com/maraisr/meros/blob/219fe95/src/browser.ts
···
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 =>
+
input.constructor.name === 'Buffer'
+
? (input as Buffer).toString()
+
: decoder!.decode(input as ArrayBuffer);
// DERIVATIVE: Copyright (c) 2021 Marais Rossouw <hi@marais.io>
// See: https://github.com/maraisr/meros/blob/219fe95/src/browser.ts