Repository navigation
fix(forms): improve select performance and ensure that selected option matches the ngModel value - #23784
fix(forms): improve select performance and ensure that selected option matches the ngModel value#23784theodorejb wants to merge 1 commit into
Conversation
|
Ref #14507 |
|
That's why “ref”, not “duplicate of”. |
|
I experience the same broken behaviour in Safari 11.0.2 EDIT Updated to 11.1.2 while we're at it, same problem still. |
|
I just tested https://angular-select-ie-bug.stackblitz.io/ in Safari on the latest version of iOS and can confirm that the bug happens there as well. |
|
@kara This is still an issue in Angular 7.0.0, affecting the latest versions of both IE and Safari. Could you please let me know if there's anything that I need to change, or additional tests I should add before this PR can be merged? |
|
@kara please have a look, and we would also need this fix in angular 4 |
|
@kara , @jasonaden, @IgorMinar is there anything I can do or @theodorejb can do to make progress on the triage or reviewing this merge request? I am willing to help. |
This problem has been around for years now, and it's still a big problem for me (and for others, too, see #14505). It would be very helpful if the proposed solution could be incorporated. Thanks a lot! |
|
@AndrewKushnir Can you please review this? It would be really nice if this bug was fixed in Angular 9. |
|
Thanks for the PR @theodorejb. Could you please rebase it on top of the latest master, so CI runs again with the most up-to-date set of tests? It'd be also helpful if you could provide some additional information regarding the problem:
Thank you. |
|
Thank you so much for the reply @AndrewKushnir. The PR has been rebased on master now and a couple code comments have been improved. I spent a bunch of time digging through the When option elements are rendered, Angular calls I made a simple JS Bin demonstrating the issue with plain HTML and JavaScript: The reason that using The only other way to fix the issue would be to somehow ensure that This PR is a minimal approach to fix the issue and add tests to ensure it isn't regressed. Later on if someone thinks of another way to solve it the tests will be in place to verify it works. Please let me know if there's any further information you need to move this forward. |
|
@AndrewKushnir can you review this again? I simplified the code further, moving the call to set the select element's value property inside the timeout and completely removing the need to conditionally set |
That should result in dropping the first update, not the second; flushing the write to the DOM in the |
|
Also @theodorejb -- your final commit message is failing lint because it needs a body >20 chars apparently. |
|
@dylhunn Thanks! I rebased now and squashed the last 4 commits with an updated message. |
|
@theodorejb Sorry about this, mind rebasing one more time? My TGP failed to get scheduled (we've been having capacity restrictions...) and I need to try it again. |
|
@dylhunn It's rebased now. |
|
TGP is running: google link Typical stack trace: |
|
@dylhunn Do the broken tests indicate a problem with this patch? If so, could a similar failing test be added to Angular itself? I'm not sure how I could debug those errors without being able to reproduce them myself. |
…n matches the ngModel value Rather than calling `writeValue()` over and over for individual option elements that are added/removed from the DOM, call it once after all the options have finished rendering via the `ngAfterViewChecked` hook. This is needed to efficiently set the select value when adding/removing options. The previous approach resulted in exponentially more `_compareValue` calls than the number of option elements (issue #41330). Furthermore, calling `writeValue()` when rendering individual option elements caused an issue in Safari and IE 11 where the first option element failed to be deselected when no option matched the select ngModel. This was because Angular set the select element's value property before appending the option's child text node to the DOM (issue #14505). Finally, this PR fixes an issue with delayed element removal when using the animations module (in all browsers). Previously when a selected option was removed (so no option matched the ngModel anymore), Angular changed the select element value before actually removing the option from the DOM. Then when the option was finally removed from the DOM, the browser would change the select value to that of the first option, even though it didn't match the ngModel (issue #18430). Fixes #41330, fixes #14505, fixes #18430.
|
This would be great to land, but unfortunately the amount of effort involved for us to safely get it submitted is too high. So we're going to close this, but thank you for your contribution. We appreciate you! |
|
Despite the countless hours I put into fixing this, I don't personally care anymore, since I moved my projects to Svelte which has been far easier to contribute to. But I feel bad for all the Angular users who are stuck with these apparently unresolvable bugs. |
|
I'm sorry about your experience with this issue. Not all issues have clear fixes and can be done in a backwards compatible way or a way that does not cause other adverse side-effects. The Angular team is committed to bringing existing applications along rather than leaving them behind with breaking changes. We do have plenty of contributors outside the team who have been able to land changes, including arturovt, ivanwonder, and JeanMeche who has recently been brought on due to his extensive involvement. |
|
The history here is also quite long, with extensive involvement from the team over the years. I cannot see each iteration of the change, but concerns with the changes cannot be invalidated. We also have to balance priorities and cannot dedicate infinite amounts of time to any one issue. I gave this another look after it was closed yesterday and verified real issues with the current iteration of the changes in the internal test failures. I hesitate to even mention this based due to the history here: I think I have addressed those issues and am truly hopeful we can finally resolve this, but I cannot make any promises. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes #41330, fixes #14505, fixes #18430.
PR Checklist
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently Angular calls the
writeValue()over and over for every individual option element that is added or removed from the DOM. This results in exponentially more_compareValuecalls than the number of option elements (issue #41330).Furthermore, calling
writeValue()when rendering individual option elements causes an issue in Safari and IE 11 where the first option element fails to be deselected when no option matches the select ngModel. This is because Angular sets the select element's value property before appending the option's child text node to the DOM (issue #14505).Finally, the current behavior causes an issue with delayed element removal when using the animations module (in all browsers). When a selected option is removed (so no option matches the ngModel anymore), Angular changes the select element value before actually removing the option from the DOM. Then when the option is finally removed from the DOM, the browser changes the select value to that of the first option, even though it doesn't match the ngModel (issue #18430).
What is the new behavior?
Rather than calling
writeValue()over and over for individual option elements that are added/removed from the DOM, call it once after all the options have finished rendering via theafterNextRenderfunction. This dramatically improves performance and results in correct behavior across all supported browsers.Does this PR introduce a breaking change?