blockui icon indicating copy to clipboard operation
blockui copied to clipboard

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

Open mnaoumov opened this issue 9 years ago • 2 comments

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

mnaoumov avatar Jun 26 '15 11:06 mnaoumov

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

  1. 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

  1. 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 avatar Jun 26 '15 12:06 mnaoumov

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
});

mnaoumov avatar Jun 26 '15 12:06 mnaoumov