Fixed cancelToken leakage; Added AbortController support;#3305
Fixed cancelToken leakage; Added AbortController support;#3305jasonsaayman merged 20 commits intoaxios:release/v0.22.0from
Conversation
Added AbortController support;
…cancel-token-leak
…el-token-leak � Conflicts: � package.json
…sending a request;
|
Any updates about feature integration in master branch ? It seems to be a very useful feature for me. |
|
Just for testing purposes, you can play around with this and some other PRs in this sandbox; |
…el-token-leak � Conflicts: � index.d.ts � lib/adapters/xhr.js
…cancel-token-leak
…el-token-leak � Conflicts: � README.md
|
any blockers? It would be nice to have that support without breaking changes. |
|
@jasonsaayman Is there any chance that this PR will be reviewed? :) |
|
@jasonsaayman I would love to see this in too |
|
Im migrating our Web applications api client from fetch to axios and we have consumers passing |
|
Would like to see this merged too. |
|
Would love this one to get in! |
|
The proposal for |
… fix/cancel-token-leak
…cancel-token-leak
|
@jasonsaayman rebased this on 0.22.0 just in case ;) |
* fix/Avoid package.json import; (#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <jasonsaayman@gmail.com> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <jasonsaayman@gmail.com> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
* fix/Avoid package.json import; (#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <jasonsaayman@gmail.com> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <jasonsaayman@gmail.com> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
* fix/Avoid package.json import; (axios#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (axios#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (axios#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <jasonsaayman@gmail.com> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (axios#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <jasonsaayman@gmail.com> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
* fix/Avoid package.json import; (axios#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (axios#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (axios#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <jasonsaayman@gmail.com> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (axios#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <jasonsaayman@gmail.com> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
The type signatures don't match on axios@0.27.2 and node-abort-controller@3.0.1, also doesn't match on abort-controller@3.0.0 The workaround is to cast it as |
| this.promise.then = function(onfulfilled) { | ||
| var _resolve; | ||
| // eslint-disable-next-line func-names | ||
| var promise = new Promise(function(resolve) { | ||
| token.subscribe(resolve); | ||
| _resolve = resolve; | ||
| }).then(onfulfilled); | ||
|
|
||
| promise.cancel = function reject() { | ||
| token.unsubscribe(_resolve); | ||
| }; | ||
|
|
||
| return promise; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Since you had removed code "config.cancelToken.promise.then(function onCanceled(cancel) " from the file named "adapter/xhr.js" in this commit, I think lines 38~52 are no longer needed.
I try to remove lines 38~52 here and then run the script "npm run test", finally find out that all tests are passed.
There was a problem hiding this comment.
Yes, but CancelToken is a public interface, so we can't be sure that user code is somehow not relying on its thenable/promise interface. IMHO, this should be kept as long as the CancelToken exists in the codebase.
This PR fixes
cancelTokenand adds an alternative way to cancel Axios request withAbortController.AbortControllersupport. I believe that using the existing API makes it easier to use the library.CancelTokenandAbortControllercan be used simultaneously (to facilitate the transition to the new API)Recently published as
axios-labnpm forkLive demo