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

WIP: Extract router providers into functions that could be tree-shakeable in the future #46215

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Jun 1, 2022

See separate commit messages

@atscott atscott requested a review from AndrewKushnir Jun 1, 2022
@atscott atscott added refactoring comp: router labels Jun 1, 2022
@ngbot ngbot bot added this to the Backlog milestone Jun 1, 2022
@ngbot ngbot bot added this to the Backlog milestone Jun 1, 2022
@atscott atscott force-pushed the routerproviders-separatecommits branch from a613847 to be21edf Compare Jun 2, 2022
atscott added 2 commits Jun 2, 2022
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.
@atscott atscott force-pushed the routerproviders-separatecommits branch 2 times, most recently from dff07b3 to 549102e Compare Jun 2, 2022
atscott added 3 commits Jun 3, 2022
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.
@atscott atscott force-pushed the routerproviders-separatecommits branch from 549102e to c471311 Compare Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: router refactoring state: WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants