-
Notifications
You must be signed in to change notification settings - Fork 53
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
refactor: migrate axios to fetch #564
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov Report
@@ Coverage Diff @@
## develop #564 +/- ##
===========================================
+ Coverage 86.96% 87.00% +0.04%
===========================================
Files 115 114 -1
Lines 23102 23094 -8
Branches 2358 2352 -6
===========================================
+ Hits 20091 20094 +3
+ Misses 2967 2956 -11
Partials 44 44
Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this PR also resolves axios adapter problem when making some http(s) API calls in chrome extension environment also?
you're right, it also works well in ServiceWorker |
I suddenly realized it is wrong, the lumos/packages/rpc/src/index.ts Lines 66 to 69 in 68e4f5b
so that we still need to support the // example for working with keepalive
const customizedFetch: typeof fetch = (request, init) => {
return globalThis.fetch(request, {
...init,
keepalive: true,
});
};
const rpc = new RPC(url, { fetch: customizedFetch }) // or if you are still working with NodeJS
import fetch from 'node-fetch'
new PRC(url, {
fetch: (request, init) => {
return fetch(request, { ...init, agent: customAgent })
}
}) |
Description
Fixes #487
This pull request updates the
@ckb-lumos/rpc
library to usefetch
instead ofaxios
. This change was made to avoid modifyingaxios
's adapter, which could potentially cause issues. By choosing a dependency without the state, Lumos can function better as a library. Thefetch
is not stateful, and it's widely supported in several runtimes, including the modern browsers, NodeJS, Deno, and BunRecently, a project using Axios and Lumos together experienced build failures, resulting in an error message that reads:
This error was caused by
lumos/packages/rpc/src/initAxiosWebworkerAdapter.ts
Lines 15 to 16 in a243f11
You may notice the
httpAgent
andhttpsAgent
were removed from the creation of axios in this pull request, but don't worry, they have never been used in Lumoslumos/packages/rpc/src/index.ts
Lines 23 to 25 in a243f11
Type of change
Please delete options that are not relevant.
How Has This Been Tested?