-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Race condition when using ngMessages with $asyncValidators #12856
Comments
One of our Material users is experiencing a similar issue (angular/material#4685) that I believe is related to this. Basically, typing very quickly in the input causes the errors to disappear. If you edit the Plunkr in the above issue to use ngMessages 1.3.15 (or 1.3.19), the issue disappears and it reappears if you use 1.4.0. You can also test this directly on the Material Site's input demo by scrolling down to the "Errors" demo and very quickly deleting/typing in the "Hourly Rate (USD)" field a few times: The Please let me know if I can help debug or provide more info. @petebacondarwin Thomas asked me to ping you an alert on this as the Angular Material community is seeing this in our Input Demo |
@jamlee1 @topherfangio @petebacondarwin I'm experiencing this same behavior in an application of mine. I've tried to create a spike to demonstrate the issue but have been unsuccessful. I've got it narrowed down to some particular areas, and believe it is an issue with ngAnimate moreso than ngMessages. In my app when I remove ngAnimate as a module for the application, this behavior goes away. In my scenario I have an asyncValidator on a form input that hits the server to check for the existence of a particular number that is entered in. This is the behavior I see: Page loads up and the form field is valid since nothing is entered into it. If I enter in a number that is invalid, the correct validation message appears via ngMessages. If I delete the number and enter in another invalid one, the message disappears and reappears with no issues. If I go from an invalid number to a valid one and back to an invalid one, everything is fine. If an invalid number is currently entered in and the validation message is displayed and I add another digit to the number (also making it an invalid number) for a split second I see a duplicate validation message appear, and then they both disappear never to return again. When debugging the last scenario mentioned above, I can see the following happen: As I said, I haven't been able to replicate this outside of my app. However, when stepping through the code of the spike I made using Chrome, I can sometimes get it to happen, only when stepping through though. It appears to be a timing issue with how the animations are handled (even though I don't have any animations associated with these validation messages). |
I'll take a look over the weekend or on Monday. |
@willisd2 said:
This is spot on. Looking for a fix... |
By the way, a quick workaround is to put an |
So the current sequence of things when typing a second character is:
What we want to happen is, either wait to attach a new message only after the previous message's node's animation has completed:
or to use a new
or to cancel the leave animation if the message is re-attached before the animation has completed. I am not sure if this is possible yet in ngAnimate. |
I think that this is the basis of a fix: angular:master...petebacondarwin:issue-12856 |
If `ngMessage` tried to add a message back in that was about to be removed after an animation, the NgMessageController got confused and tried to detach the newly added message, when the pending node was destroyed. This change applies a unique `attachId` to the message object and its DOM node when it is attached. This is then checked when a DOM node is being destroyed to prevent unwanted calls to `detach`. Closes angular#12856
I have a fix here: #12903 |
If `ngMessage` tried to add a message back in that was about to be removed after an animation, the NgMessageController got confused and tried to detach the newly added message, when the pending node was destroyed. This change applies a unique `attachId` to the message object and its DOM node when it is attached. This is then checked when a DOM node is being destroyed to prevent unwanted calls to `detach`. Closes angular#12856 Closes angular#12903
Don't mail me
DISCLAIMER Any views or opinions presented in this email are solely those of the DISCLAIMER Any views or opinions presented in this email are solely those of the |
If `ngMessage` tried to add a message back in that was about to be removed after an animation, the NgMessageController got confused and tried to detach the newly added message, when the pending node was destroyed. This change applies a unique `attachId` to the message object and its DOM node when it is attached. This is then checked when a DOM node is being destroyed to prevent unwanted calls to `detach`. Closes #12856 Closes #12903
The issue is that $asyncValidators will set the validity to undefined while it fulfills its promise, which will cause the error to briefly go away. At this point, ngMessage's render method will process the $errors (which will be {}), and will detach the messageCtrl. But before that is complete, the async validator finishes and sets the error back to true, and ngMessage's render method is run. Then $destroy handler is invoked and ngMessage will deregister the message node, causing the message to go away and never come back.
See the error in action:
https://gist.github.com/anonymous/1bd3f9b6cb17498e73c0
The text was updated successfully, but these errors were encountered: