Replace setImmediate with setTimeout 0#14
Merged
mjwwit merged 1 commit intomjwwit:masterfrom Jul 16, 2023
Merged
Conversation
Author
|
Converted to draft, because appearently my editor decided to add some formatting |
Owner
|
Thanks for this! I'll have a look at it later this week. |
Owner
|
I've just released version 2.1.1 on npm which includes your fix. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are a few references to setImmediate, https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate which was only partially adopted by node, and breaks lots of jsdom things.
I think it's usage leads to lots of downstream headaches for users of the lib. See the google results: https://www.google.com/search?q=jsdom++setImmediate+is+not+defined+site:github.com&client=firefox-b-1-d&sxsrf=AB5stBg2qBNE8pVK3DI98qSnmKt7yqTREg:1689006813782&sa=X&ved=2ahUKEwiGgKLZyISAAxVYie4BHdkhB4IQrQIoBHoECBUQBQ&biw=1479&bih=1010&dpr=2#ip=1
This obviously isn't the only lib that uses setImmediate, but it's a big one that I've had to work around on a few projects now.
This PR replaces the use of setImmediate with setTimeout(() => {...}, 0), which is functionally very similar. https://nodejs.dev/en/learn/understanding-setimmediate/
For the purposes of this library, I don't see any reason to use setImmediate over setTimeout.