Skip to content

fix(router): fragment must be a string#37334

Closed
MatthiasKunnen wants to merge 2 commits intoangular:masterfrom
MatthiasKunnen:issue-23894-fragment-null
Closed

fix(router): fragment must be a string#37334
MatthiasKunnen wants to merge 2 commits intoangular:masterfrom
MatthiasKunnen:issue-23894-fragment-null

Conversation

@MatthiasKunnen
Copy link
Copy Markdown
Contributor

@MatthiasKunnen MatthiasKunnen commented May 28, 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?

ActivatedRoute.fragment is typed as Observable<string> but can emit both null and undefined due to incorrect non-null assertion.

Issue Number: Fixes #23894

What is the new behavior?

The non-null assertions have been removed and fragment will now be an empty string instead of null. This behavior is consistent with window.location.hash.

Does this PR introduce a breaking change?

  • Yes
  • No

ActivatedRoute.fragment will no longer be null when the URL does not have a fragment. Difference for fragment values:

Old New
https://e.g null ''
https://e.g# '' ''

Applications should check for an empty string instead of null in order to determine that no fragment is set.

@pullapprove pullapprove bot requested a review from atscott May 28, 2020 19:43
ActivatedRoute.fragment was typed as Observable<string> but could emit
both null and undefined due to incorrect non-null assertion. These
non-null assertions have been removed and fragment has been ensured to
be a string.

Fragment being an empty string is consistent with window.location.hash.

BREAKING CHANGE:
ActivatedRoute.fragment will no longer be null when the URL does not
have a fragment. Difference for fragment values:

|              | Old  | New |
|--------------|------|-----|
| https://e.g  | null | ''  |
| https://e.g# | ''   | ''  |

Fixes angular#23894.
@MatthiasKunnen MatthiasKunnen force-pushed the issue-23894-fragment-null branch from 69863a6 to f87fd49 Compare May 28, 2020 19:51
@atscott
Copy link
Copy Markdown
Contributor

atscott commented May 28, 2020

Hi @MatthiasKunnen, as I mentioned in the issue report, I think the correct fix is to update the type rather than convert null to empty string. #23894 (comment)

@MatthiasKunnen
Copy link
Copy Markdown
Contributor Author

MatthiasKunnen commented May 28, 2020

I was already making this change and missed your comment.

Two questions about changing the type:

  • Should undefined be converted to null? I assume so
  • What value should fragment have in this case: https://e.g/#? null or empty string?

@MatthiasKunnen
Copy link
Copy Markdown
Contributor Author

Might be interesting, according to the spec internally, the URL fragment is string | null as is UrlTree's. However, publicly, it is an empty string in case of null. Something might be said about consistency with the HTML spec. The decision is yours of course.

@atscott
Copy link
Copy Markdown
Contributor

atscott commented May 28, 2020

Undefined should be converted to null. You can also mark your or as fixing this: #34197

The answer to your second question I think is a bit harder to answer. I personally think that should be empty string( see #29683 (comment) ). What’s the current behavior?

@MatthiasKunnen
Copy link
Copy Markdown
Contributor Author

Current behavior is an empty string

@MatthiasKunnen
Copy link
Copy Markdown
Contributor Author

I propose I close this PR and make a new one since this PR's intentions have changed and it might get confusing. Agreed?

@atscott
Copy link
Copy Markdown
Contributor

atscott commented May 28, 2020

I propose I close this PR and make a new one since this PR's intentions have changed and it might get confusing. Agreed?

Yea, that sounds good. Thanks!

@angular-automatic-lock-bot
Copy link
Copy Markdown

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 Jun 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type declaration for ActivatedRoute.fragment doesn't declare possible null values

3 participants