Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 62f1449

Browse files
JiaLiPassionmhevery
authored andcommitted
fix #569, request will cause updateTaskCount failed if we call abort multipletimes (#570)
the fix is check whether the xhr has been aborted before abort the request
1 parent e92f934 commit 62f1449

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: lib/browser/browser.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ function patchXHR(window: any) {
125125
const task: Task = findPendingTask(self);
126126
if (task && typeof task.type == 'string') {
127127
// If the XHR has already completed, do nothing.
128-
if (task.cancelFn == null) {
128+
// If the XHR has already been aborted, do nothing.
129+
// Fix #569, call abort multiple times before done will cause
130+
// macroTask task count be negative number
131+
if (task.cancelFn == null || (task.data && (<XHROptions>task.data).aborted)) {
129132
return;
130133
}
131134
task.zone.cancelTask(task);

Diff for: test/browser/XMLHttpRequest.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,18 @@ describe('XMLHttpRequest', function() {
195195
};
196196
});
197197
});
198+
199+
it('should keep taskcount correctly when abort was called multiple times before request is done',
200+
function() {
201+
testZone.run(function() {
202+
const req = new XMLHttpRequest();
203+
req.open('get', '/', true);
204+
req.send();
205+
req.addEventListener('readystatechange', function(ev) {
206+
if (req.readyState >= 2) {
207+
req.abort();
208+
}
209+
});
210+
});
211+
});
198212
});

0 commit comments

Comments
 (0)