You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While perfectly reasonable on the surface, running it actually hangs the browser. The log statement is never printed and the entire UI freezes in Chrome. Add a button to the HTML, try to click it and it won't animate. It also locks down the tab and refreshes fail. You have to completely kill the tab and re-open a new one to try again. The same thing happens if you try to use async/await patterns.
I believe the problem here is the Module.then() function. My lib variable is effectively a Module (looking at the obfuscated source here) and the Module has a then() function (reproduced below and pretty-printed).
When resolved in a Promise, it sees that the result has a .then() and considers it Thenable. It invokes .then() and returns it's result, expecting a Promise or another Thenable which will chain to an eventual result.
However, .then() actually returns Module which is Thenable with the same function. This endlessly recurses as the Promise continually wraps the Module and invokes .then(). This adds microtasks to the queue forever and so the browser never moves on to paint the UI.
I'm guessing this library was written in a time before the native Promise object, but it should either be changed to be compatible with Thenable semantics or have this function renamed to something else.
The text was updated successfully, but these errors were encountered:
Consider the following JavaScript code:
While perfectly reasonable on the surface, running it actually hangs the browser. The log statement is never printed and the entire UI freezes in Chrome. Add a button to the HTML, try to click it and it won't animate. It also locks down the tab and refreshes fail. You have to completely kill the tab and re-open a new one to try again. The same thing happens if you try to use
async/await
patterns.I believe the problem here is the
Module.then()
function. Mylib
variable is effectively aModule
(looking at the obfuscated source here) and theModule
has athen()
function (reproduced below and pretty-printed).When resolved in a
Promise
, it sees that the result has a.then()
and considers itThenable
. It invokes.then()
and returns it's result, expecting aPromise
or anotherThenable
which will chain to an eventual result.However,
.then()
actually returnsModule
which isThenable
with the same function. This endlessly recurses as thePromise
continually wraps theModule
and invokes.then()
. This adds microtasks to the queue forever and so the browser never moves on to paint the UI.I'm guessing this library was written in a time before the native
Promise
object, but it should either be changed to be compatible withThenable
semantics or have this function renamed to something else.The text was updated successfully, but these errors were encountered: