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
Deferred: Deprecate setTimeout() usage under latest browsers. #5114
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for the PR. Please fix the reported ESLint violations. Also, we don't want to expose a new method, please keep it internal. Once that's done, we should see the actual test suite running. Also, do we need a manual queue when using |
Hi, thank you, pleased you guys are positive about those kind of changes. Well, the manual queue for queueMicrotask can be seen as subjective yes, i think it could help the browser but probably we won't prevent much overhead there. Also, i was expecting it'd be fine exposing a method so that for example i could then replace it with my own scheduler. If these are no-go then we can simplify this a lot, will now proceed to do so. |
6d523f3
to
fd13506
Compare
@diegocr you need to rebase the PR to avoid the issues on |
Cool, done 🚀 |
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.
Sorry for a late review. I have one doubt about the testing strategy.
this.sandbox.stub( jQuery, "readyException" ).callsFake( function( error ) { | ||
assert.strictEqual( error.message, expected, "jQuery.readyException called with unexpected error" ); | ||
window.setTimeout( function() { | ||
throw error; | ||
} ); | ||
} ); |
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.
Why mocking jQuery.readyException
? Can't this test be done in a similar way as the setTimeout
one? In that case, maybe we could just keep a single test?
Summary
Hi there, as you may know, Chrome/ium has been lately aggressively throttling background tabs, this may result in those setTimeout()-based promises/deferreds to never resolve until the tab becomes active again.
This PR is an attempt to prevent that, by using queueMicrotask under browsers supporting it. Also, the logic has been changed to dispatch those processes in bulk instead of individually, since the main reason for that throttling seems to be by having too many concurrent setTimeout()s running.
This implements a new
jQuery.asap()
function that will use eitherqueueMicrotask
orsetTimeout
for older browsers.I've observed that around this whole codebase there are several other uses of that
window.setTimeout( func )
pattern so perhaps I should move thisjQuery.asap()
elsewhere to be used in place of those as well (as part of another PR) ?Thanks!
Checklist