BlockUI overrides blockUI.history with new data without restoring the previous.

BlockUI overrides blockUI.history with new data without restoring the previous.

Consider this scenario:

You have blockUI block the page with the message being an element a div with id #dialog for example.
Inside that div there is a button that does the following:
  1. Unblocks the page
  2. Executes some functionality which may result to an error. For example a failed ajax call.
  3. On that ajax failure callback you update an observable array with the error(-s) that occurred.
  4. On that observable array there is a subscription that when the length of the array is > 0 it will block the page and have as block message a div with an id #errorDialog.

So far the flow seems logical.

But what is happening is this :
While the unblock (reset function) is being executed within a setTimeout, the subscription notifier has been fired which invokes again the block. At this moment and before the new block is executed the blockUI.history has the #dialog element. The block continues execution and replaces the blockUI.history with the #errorDialog element.
The reset function for the first unblock is being executed but because
the $el.data('blockUI.isBlocked') = 1 the #dialog element will is never restored.

So the second time you try invoke the #dialog you get an error because the node does not exist anymore.


Here is a jsfiddle to demonstrate the issue
http://jsfiddle.net/a98gN/43/