This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experimental): Use the native
fetch
built into Node 18+ (#…
…1802) # Summary OK, so here's what I'm thinking. `node-fetch` is in this weird state where: - they refuse to build CommonJS bundles for the 3.x line - the 2.x line supports `HttpAgent` - note that browsers will never support `HttpAgent` - the 2.x line does not support HTTP/2 This means that we're taking on a huge dependency and exposing its config through web3.js, but will never end up in the ideal state (HTTP/2 support everywhere). In this PR, we throw in the towel and make the _default_ transport that ships with web3.js API compatible with the `fetch` in both Node and browsers. From that point: - We could write our own HTTP/2 transport that's API compatible with `fetch()` and ship that - Someone _else_ could write an all-singing, all-dancing transport _specifically_ for Node and open source it Addresses #1680.
- Loading branch information
1 parent
762ff13
commit d32897d
Showing
6 changed files
with
3 additions
and
102 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
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 |
---|---|---|
@@ -1,8 +1,2 @@ | ||
// When building the browser bundle, this import gets replaced by `globalThis.fetch`. | ||
import fetchImpl from 'node-fetch'; | ||
|
||
export default typeof globalThis.fetch === 'function' | ||
? // The Fetch API is supported experimentally in Node 17.5+ and natively in Node 18+. | ||
globalThis.fetch | ||
: // Otherwise use the polyfill. | ||
fetchImpl; | ||
// TODO(https://github.com/solana-labs/solana-web3.js/issues/1787) Write HTTP/2 implementation. | ||
export default globalThis.fetch; // The Fetch API is supported natively in Node 18+. |
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
38 changes: 0 additions & 38 deletions
38
packages/rpc-transport/src/transports/http/__tests__/http-transport-agent-test.ts
This file was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.