Skip to content

fix(router): ensure routerLinkActive updates when associated routerLinks change #38349

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

Closed
wants to merge 2 commits into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Aug 5, 2020

This commit introduces a new subscription in the routerLinkActive directive which triggers an update
when any of its associated routerLinks have changes. RouterLinkActive not only needs to know when
links are added or removed, but it also needs to know about if a link it already knows about
changes in some way.

Quick note that from...mergeAll is used instead of just a simple
merge (or scheduled...mergeAll) to avoid introducing new rxjs
operators in order to keep bundle size down.

Fixes #18469

@atscott atscott added type: bug/fix area: router target: patch This PR is targeted for the next patch release router: directives RouterLink, RouterLinkActive, RouterOutlet etc. labels Aug 5, 2020
@ngbot ngbot bot added this to the needsTriage milestone Aug 5, 2020
@atscott
Copy link
Contributor Author

atscott commented Aug 5, 2020

presubmit

@mmalerba mmalerba self-requested a review August 5, 2020 19:12
@atscott atscott marked this pull request as ready for review August 5, 2020 19:14
@atscott atscott force-pushed the rla branch 3 times, most recently from 7479599 to 817591f Compare August 5, 2020 21:13
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (just a couple nits) 👍

Reviewed-for: public-api

@mary-poppins
Copy link

You can preview 3abec29 at https://pr38349-3abec29.ngbuilds.io/.
You can preview 7479599 at https://pr38349-7479599.ngbuilds.io/.
You can preview 817591f at https://pr38349-817591f.ngbuilds.io/.

@mary-poppins
Copy link

You can preview de6aaec at https://pr38349-de6aaec.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 87ea2f1 at https://pr38349-87ea2f1.ngbuilds.io/.

@mary-poppins
Copy link

You can preview d0f41ba at https://pr38349-d0f41ba.ngbuilds.io/.

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@atscott atscott force-pushed the rla branch 2 times, most recently from 0ae1d28 to ffcefd8 Compare August 6, 2020 23:01
@mary-poppins
Copy link

You can preview ffcefd8 at https://pr38349-ffcefd8.ngbuilds.io/.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-for: public-api

…nks change

This commit introduces a new subscription in the `routerLinkActive` directive which triggers an update
when any of its associated routerLinks have changes. `RouterLinkActive` not only needs to know when
links are added or removed, but it also needs to know about if a link it already knows about
changes in some way.

Quick note that `from...mergeAll` is used instead of just a simple
`merge` (or `scheduled...mergeAll`) to avoid introducing new rxjs
operators in order to keep bundle size down.

Fixes angular#18469
@mary-poppins
Copy link

You can preview 95af0b8 at https://pr38349-95af0b8.ngbuilds.io/.

Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-For: public-api

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@ContentChildren(RouterLink, {descendants: true}) links!: QueryList<RouterLink>;
// TODO(issue/24571): remove '!'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I am against removing these comments unless the ! is removed (somehow) or replacing the comment with a reason why the ! can be retained.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I guess Angular developers are aware that queries are only available after the appropriate hook has been called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought process was that they could "technically" be undefined until afterContentInit but are reliably initialized after that. And that we could really never make this ? instead so the comment isn't really actionable in that way. I did some more reading in the issue report and found these guidelines that support keeping ! as well:

the field is reliably initialized, but TS cannot infer that (initialization can occur outside the ctor, for example), so ! should be kept.

#24571 (comment)
I think ContentChildren and ViewChildren could be considered "reliably initialized" after the correct lifecycle hooks.

If the field is annotated with @ViewChildren or @ContentChildren - Add back '!' - c).

#24571 (comment)

@mary-poppins
Copy link

You can preview e21e492 at https://pr38349-e21e492.ngbuilds.io/.

@atscott atscott removed the request for review from pkozlowski-opensource August 17, 2020 19:32
@atscott atscott added the action: merge The PR is ready for merge by the caretaker label Aug 17, 2020
@atscott atscott closed this in e0e5c9f Aug 17, 2020
atscott added a commit that referenced this pull request Aug 17, 2020
…nks change (#38349)

This commit introduces a new subscription in the `routerLinkActive` directive which triggers an update
when any of its associated routerLinks have changes. `RouterLinkActive` not only needs to know when
links are added or removed, but it also needs to know about if a link it already knows about
changes in some way.

Quick note that `from...mergeAll` is used instead of just a simple
`merge` (or `scheduled...mergeAll`) to avoid introducing new rxjs
operators in order to keep bundle size down.

Fixes #18469

PR Close #38349
atscott added a commit to atscott/angular that referenced this pull request Aug 18, 2020
…routerLinks change (angular#38349)"

This reverts commit e0e5c9f.
Failures in Google tests were detected.
atscott added a commit that referenced this pull request Aug 18, 2020
…routerLinks change (#38349)" (#38511)

This reverts commit e0e5c9f.
Failures in Google tests were detected.

PR Close #38511
atscott added a commit that referenced this pull request Aug 18, 2020
…routerLinks change (#38349)" (#38511)

This reverts commit e0e5c9f.
Failures in Google tests were detected.

PR Close #38511
subratpalhar92 pushed a commit to SUBRATPALHAR-ALL-JAVASCRIPT/angular that referenced this pull request Aug 29, 2020
…nks change (angular#38349)

This commit introduces a new subscription in the `routerLinkActive` directive which triggers an update
when any of its associated routerLinks have changes. `RouterLinkActive` not only needs to know when
links are added or removed, but it also needs to know about if a link it already knows about
changes in some way.

Quick note that `from...mergeAll` is used instead of just a simple
`merge` (or `scheduled...mergeAll`) to avoid introducing new rxjs
operators in order to keep bundle size down.

Fixes angular#18469

PR Close angular#38349
subratpalhar92 pushed a commit to SUBRATPALHAR-ALL-JAVASCRIPT/angular that referenced this pull request Aug 29, 2020
…routerLinks change (angular#38349)" (angular#38511)

This reverts commit e0e5c9f.
Failures in Google tests were detected.

PR Close angular#38511
subratpalhar92 added a commit to SUBRATPALHAR-ALL-JAVASCRIPT/angular that referenced this pull request Aug 31, 2020
subratpalhar92 added a commit to SUBRATPALHAR-ALL-JAVASCRIPT/angular that referenced this pull request Aug 31, 2020
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…nks change (angular#38349)

This commit introduces a new subscription in the `routerLinkActive` directive which triggers an update
when any of its associated routerLinks have changes. `RouterLinkActive` not only needs to know when
links are added or removed, but it also needs to know about if a link it already knows about
changes in some way.

Quick note that `from...mergeAll` is used instead of just a simple
`merge` (or `scheduled...mergeAll`) to avoid introducing new rxjs
operators in order to keep bundle size down.

Fixes angular#18469

PR Close angular#38349
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…routerLinks change (angular#38349)" (angular#38511)

This reverts commit e0e5c9f.
Failures in Google tests were detected.

PR Close angular#38511
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: router cla: yes risk: low router: directives RouterLink, RouterLinkActive, RouterOutlet etc. target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

routerLinkActive not updating when routerLink changed
8 participants