remotipart icon indicating copy to clipboard operation
remotipart copied to clipboard

Race condition between rails-ujs and remotipart means "submit" buttons aren't disabled

Open danbernier opened this issue 10 years ago • 1 comments

Hi,

I think @treznick and I found a race condition between remotipart and jquery-ujs that is preventing buttons from being disabled ala data-disable-with, added in issue #31.

In development, we see UJS disable the buttons, then re-enable them on the ajax:aborted:file event, and then remotipart re-disables them for the ajax file upload.

But in production, UJS disables the buttons, then remotipart re-disables them, and then UJS enables them. It appears to the user that the buttons are never disabled.

Changing the remotipart setTimeout delay for re-disabling the buttons to 40ms, like so:

setTimeout(function(){ $.rails.disableFormElements(form); }, 40); // old timeout was 20

...seems to fix the race condition, but this seems like a brittle solution.

Our problem feels very similar to #338, but not quite the same.

Is there a better way to guarantee the order?

danbernier avatar Nov 21 '14 16:11 danbernier

Update: as of now, we have our own series of setTimeout callbacks at something like 10, 30, and 200ms, to re-disable the buttons, as long as there's a 'pending' flag on the form (which we're adding when the form is submitted, and removing when the response comes in). It's sloppy, but it works.

Would love to hear thoughts on fixing the core issue. Anything we can do to help?

danbernier avatar Nov 25 '14 20:11 danbernier