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

fix(router): Allow undefined inputs on routerLink #39151

Closed
wants to merge 1 commit into from

Conversation

PowerKiKi
Copy link
Contributor

@PowerKiKi PowerKiKi commented Oct 7, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

When compiling in the most strict mode, the following will throw error, but it is should be valid:

    <a [routerLink]="['foo']" [fragment]="null">some link</a>

The error would be similar to:

    ERROR in foo.component.html:2:52 - error TS2322: Type 'null' is not assignable to type 'string'.
    
    2         <a [routerLink]="['foo']" [fragment]="null">some link</a>

What is the new behavior?

This make it coherent with typing of Router.createUrlTree to which those inputs are directly forwarded to. And hence it allow to pass undefined, null or a value to the routerLink directive.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Oct 7, 2020
@pullapprove pullapprove bot requested a review from atscott Oct 7, 2020
Copy link
Contributor

@atscott atscott left a comment

Hi @PowerKiKi, thanks for the PR. Just a couple notes:

  • Please fix the lint failure by running yarn ng-dev format files packages/router/src/directives/router_link.ts
  • Please fix the test failure by running yarn bazel run //packages/router:router_api.accept
  • On the surface, this is a really good quality of life change. These types should have been aligned from the very beginning. Unfortunately, we have to consider this a breaking change because this could produce new TS errors (i.e. Object is possible 'null' or 'undefined') in locations that access these public fields. I'll need to run a global presubmit to see how often this generally occurs in user code. If it causes a lot of breakages, we'll need to think about adding a migration to automatically add the null assertion operator for those.
  • Because of the note above, please add a BREAKING CHANGE: footer to your commit message and just quickly highlight what changed and what needs to be done to fix the build failure if devs see this when upgrading to v11
  • Lastly, the feature freeze for v11 is next week so depending on the results of the testing, it's quite likely that this is going to miss the cut-off and will need to be pushed back until v12 ☹️ Hopefully testing goes smoothly though! 🤞

@atscott
Copy link
Contributor

@atscott atscott commented Oct 9, 2020

initial presubmit (no failures due to this change 🥳 )

@atscott
Copy link
Contributor

@atscott atscott commented Oct 9, 2020

global presubmit shows now breakages due to this change.

@PowerKiKi This means there's a pretty strong indication that the change here will not break user code in the vast majority of cases. I think it'd still be a good idea to add the breaking change note to the commit message as mentioned above. The message can be pretty minimal, given that this is rare / will never happen.

@PowerKiKi PowerKiKi force-pushed the relax-router-link branch 2 times, most recently from 179ce30 to 65b4bbd Compare Oct 11, 2020
@PowerKiKi
Copy link
Contributor Author

@PowerKiKi PowerKiKi commented Oct 11, 2020

Thank you for the review, I fixed the code style, commit message and accepted the API changes in the golden files.

Hopefully that should be enough for merging.

This make it coherent with typing of Router.createUrlTree to which
those inputs are directly forwarded to. And hence it allow to pass
`undefined`, `null` or a value to the routerLink directive.

BREAKING CHANGE: in most cases this should not break, but if you were
accessing the values of `queryParams`, `fragment` or `queryParamsHandling`
you might need to relax the typing to also accept `undefined` and `null`.

Signed-off-by: Adrien Crivelli <adrien.crivelli@gmail.com>
Copy link
Contributor

@atscott atscott left a comment

reviewed-for: fw-router
reviewed-for: public-api

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Reviewed-for: public-api

Anyone expecting these to be defined is probably in trouble any way, right?
Since the inputs are not required on the directive they could indeed be undefined at runtime.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Reviewed-for: public-api

@PowerKiKi PowerKiKi deleted the relax-router-link branch Oct 13, 2020
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Nov 13, 2020

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 Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants