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
RouterLinkActive race condition with RouterLink created dynamically from template ref #18983
Comments
…cking the children Closes angular#18983
Any chance the fix for this introduced an infinite loop of some sort (seems like in recent history RouterLinkActive was prone to that already). With 4.4.6 I'm experiencing a hang and 100% CPU when using a component that pretty much only uses RouterLinkActive. On 4.4.5 it works fine and the 4.4.6 changelog is pretty small. |
…cking the children (angular#19449) Closes angular#18983 PR Close angular#19449
…cking the children (angular#19449) Closes angular#18983 PR Close angular#19449
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. |
I'm submitting a...
Current behavior
RouterLinkActive sets
isActive
in an immediately resolved Promise, but between creating the Promise and resolving it, the links may have changed their href.This is manifested in the following plunker: http://plnkr.co/edit/iio3c6erK8H3qtn93l7c?p=preview
Apologies if the reproduction is not minimal enough. When
container.addLink()
is called, the container creates a new embedded view with the implicit data'my-link'
. That newly created view has a router link that uses the implicit data as its link.It appears that router's update function is called twice: when the router link is created from the
createEmbeddedView
call in container, and then again when change detection runs to provide the implicit data. When theupdate()
runs the first time, it sees that the link is undefined, which matches the current route. It sets a Promise to resolve settingisActive
to true. Before that promise resolves,update()
is called again with the'my-link'
href but does nothing becauseisActive
is still false at the moment. After the thread completes, the promise resolves and incorrectly setsisActive
to true.Calling
rla.update()
manually corrects the RouterLinkActive'sisActive
.Expected behavior
The router link active should reflect
isActive
properly and not have any race condition with the Promise.Minimal reproduction of the problem with instructions
See http://plnkr.co/edit/iio3c6erK8H3qtn93l7c?p=preview
What is the motivation / use case for changing the behavior?
Caused a bug in the Angular Material CDK Table. See issue here: angular/components#6701
Environment
The text was updated successfully, but these errors were encountered: