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
WIP: Extract router providers into functions that could be tree-shakeable in the future #46215
Draft
atscott
wants to merge
5
commits into
angular:main
Choose a base branch
from
atscott:routerproviders-separatecommits
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−136
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alfaproject
reviewed
Jun 2, 2022
a613847
to
be21edf
Compare
Extracting the `'enableTracing'` option to a provider moves us towards thinking about a world where `ExtraOptions` doesn't exist to control behaviors that are opt-in/opt-out. Instead, these behaviors could be controlled by the presence (or lackthereof) of the providers which has the functionality. This is relevant to a world in which we no longer have the `RouterModule` but instead have something like `provideRouter` where the features are tree-shakeable. This change does not affect the current `RouterModule.forRoot` behavior, tree-shakeability of the option, or existence of `enableTracing` on the `ExtraOptions`.
Rather than using a `provideLocationStrategy` function, the `useHash` can simply provide one strategy or another. The current factory function does not change how the dependencies are used.
dff07b3
to
549102e
Compare
Extracting the scroller to a provider moves us towards thinking about a world where `ExtraOptions` doesn't exist to control behaviors that are opt-in/opt-out. Instead, these behaviors could be controlled by the presence (or lackthereof) of the providers which has the functionality. This is relevant to a world in which we no longer have the `RouterModule` but instead have something like `provideRouter` where the features are tree-shakeable. This change does not affect the current `RouterModule.forRoot` behavior, tree-shakeability of the option, or existence of the options related to the router scroller (scrollPositionRestoriation, anchorScrolling, scrollOffset).
Extracting preloading to a provider moves us towards thinking about a world where `ExtraOptions` doesn't exist to control behaviors that are opt-in/opt-out. Instead, these behaviors could be controlled by the presence (or lackthereof) of the providers which has the functionality. This is relevant to a world in which we no longer have the `RouterModule` but instead have something like `provideRouter` where the features are tree-shakeable. This change _does not_ make the `RouterPreloader` tree-shakeable inside `RouterModule.forRoot` because the compiler cannot statically determine whether it's needed. However, in the `provideRouter` world without `forRoot`, preloading could be exposed through the provider function instead, making the `RouterPreloader` and `PreloadingStrategy` implementations tree-shakeable for those that don't use it (which is the default - no preloading). Is this a BREAKING CHANGE because the RouterPreloader is not provided by default in the `RouterModule` anymore? Would applications attempt to inject `RouterPreloader` without defining a preloading strategy via the `ExtraOptions`? The only other way to get custom preloading is to write a different provider for `RouterPreloader` and in that case, things should still work.
…providers This change separates the router initializer into different providers. While it does not actually change the tree-shakeablity or the public API, it does move us towards a world that _could_ do this. That is, instead of `initialNavigation: 'disabled'`, users could use `provideDisabledInitialNavigation` in the `bootstrapApplication` call and none of the code for `initialNavigation: 'enabledBlocking'` would be included in the application.
549102e
to
c471311
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
See separate commit messages