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

feat: use undici as fetch polyfill #9106

Merged
merged 2 commits into from
Mar 22, 2024
Merged

feat: use undici as fetch polyfill #9106

merged 2 commits into from
Mar 22, 2024

Conversation

jacob-ebey
Copy link
Member

@jacob-ebey jacob-ebey commented Mar 22, 2024

Use undici as our fetch polyfill going forward. This will allow us to firstly (and my my favorite part), stop maintaining our own, and secondly and arguably more important, will allow us to smoothly upgrade our users to the Node.js fetch when they are on a node 20+ as they will already be using it via the polyfill. Undici is the node fetch implementation, and now all our installGlobals() will be doing is giving you the latest version regardless of your node version, and I think that's pretty sweet.

Closes: #

  • Docs
  • Tests

Testing Strategy:

Copy link

changeset-bot bot commented Mar 22, 2024

⚠️ No Changeset found

Latest commit: e1eecd1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@jacob-ebey jacob-ebey force-pushed the undici branch 4 times, most recently from ee3dec9 to 1e767c1 Compare March 22, 2024 00:27
feat: use native node web stream
Copy link
Member

@mjackson mjackson left a comment

Choose a reason for hiding this comment

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

this looks pretty sweet! 🙌 Nice work!

One small question: It seems like in addition to installing the fetch family in our polyfill, we should also install ReadableStream and WritableStream, as well as any other stream classes provided by undici. Do you agree @jacob-ebey ?


installGlobals();
require("@remix-run/node").installGlobals();
Copy link
Member

Choose a reason for hiding this comment

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

It seems like installGlobals should also install TextDecoder, TextEncoder, ReadableStream, and WritableStream, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a JSDom issue here.

@garand
Copy link
Contributor

garand commented Mar 22, 2024

Keep an eye out for this bug. I moved to Undici on a project and had to switch off because the API I was working with wasn't including a content-length.

nodejs/undici#1540

@jacob-ebey jacob-ebey merged commit ad83e53 into dev Mar 22, 2024
5 checks passed
@jacob-ebey jacob-ebey deleted the undici branch March 22, 2024 17:05
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Mar 22, 2024
@jacob-ebey
Copy link
Member Author

Keep an eye out for this bug. I moved to Undici on a project and had to switch off because the API I was working with wasn't including a content-length.

nodejs/undici#1540

I added a test against this and it appears to have been fixed at some point: nodejs/undici#2995

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon CLA Signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants