malsup / blockui

jQuery BlockUI Plugin
http://jquery.malsup.com/block/
1.69k stars 506 forks source link

DOM element as message functionality is not reliable in race condition scenarios #122

Open mnaoumov opened 9 years ago

mnaoumov commented 9 years ago

See http://jsfiddle.net/mnaoumov/bhLbgdp4/

mnaoumov commented 9 years ago

I investigated the problem and I found the reason but I don't see how to fix it properly.

1) https://github.com/malsup/blockui/blob/2.70/jquery.blockUI.js#L468 - on unblockUI we set data blockUI.isBlocked=0

then on 2) https://github.com/malsup/blockui/blob/2.70/jquery.blockUI.js#L494 we starting to fade out and set callback

3) https://github.com/malsup/blockui/blob/2.70/jquery.blockUI.js#L496 which returns DOM element to its parent

On 4) https://github.com/malsup/blockui/blob/2.70/jquery.blockUI.js#L256 it is checked for data blockUI.isBlocked

I debugged my scenario and 4) is executed after 1) but before 3), so the DOM element is still a part of blockUI generated div and it is being captured as a parent of the DOM element. Then this "parent" is being removed from DOM.

And then on the next $.blockUI() call it fails on

5) https://github.com/malsup/blockui/blob/2.70/jquery.blockUI.js#L279

because node variable is undefined because our "DOM element" doesn't belong to DOM anymore.

mnaoumov commented 9 years ago

Actually this issue exists even if we have ignoreIfBlocked = false but in this case I don't know how to properly detect this case.

In my project I kinda resolved this issue by using

$.blockUI({
    message: $(".progress-indicator").clone(),
    ignoreIfBlocked: true
});