Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 15, 2021

Conversation

kitten
Copy link
Member

@kitten kitten commented Oct 14, 2021

Resolves #2026

Prevent Buffer from being automatically replaced and polyfilled by Webpack's automatic Node.js polyfilling. We achieve this by not using the global and instead check the constructor name of the object we receive.

@kitten kitten requested a review from JoviDeCroock October 14, 2021 18:12
@changeset-bot
Copy link

changeset-bot bot commented Oct 14, 2021

🦋 Changeset detected

Latest commit: cd6c8b1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@urql/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

typeof Buffer !== 'undefined' && Buffer.isBuffer(input)
? input.toString()
: decoder!.decode(input);
input.constructor.name === 'Buffer'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tricky check without referencing Buffer directly!

I was thinking of a potential alternate of just detecting isBuffer and using it -- also not 100%, but would allow subclasses of Buffer...

typeof input.constructor.isBuffer === 'function' && input.constructor.isBuffer(input)

No big deal either way, but just one other thought!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with either 👍 I double checked the Node reference implementation before sending in this change and they seem to just be doing a constructor check, so either should be alright 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked the Node reference implementation before sending in this change and they seem to just be doing a constructor check

Oh haha, that sounds like a good approach then 😂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kitten kitten merged commit 922d4a1 into main Oct 15, 2021
@kitten kitten deleted the fix/buffer-autopolyfill branch October 15, 2021 20:09
@urql-ci urql-ci mentioned this pull request Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants