Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
danbernier opened this issue Nov 21, 2014 · 1 comment

Comments

@danbernier
Copy link

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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant