-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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(compiler-cli): add support for more than 2 levels of nested lazy routes #13678
Conversation
4152054
to
3e680be
Compare
…oad routes paths The change avoids the compiler CLI internal API from mismatching the following case as lazy loading ``` import { NonLazyLoadedModule } from './non-lazy-loaded/non-lazy-loaded.module'; export function getNonLazyLoadedModule() { return NonLazyLoadedModule; } export const routes = [ { path: '/some-path', loadChildren: getNonLazyLoadedModule } ]; ``` The output of the check is later passed to `RouteDef.fromString()`, so, it makes sense to be only a string. Fixes angular/angular-cli#3204
3e680be
to
b8158f0
Compare
…routes This change adds Compiler CLI support for any level of nesting for lazy routes. For example `{app-root}/lazy-loaded-module-1/lazy-loaded-module-2/lazy-loaded-module-3` Where `lazy-loaded-module-3` is lazy loaded from `lazy-loaded-module-2`, and `lazy-loaded-module-2` is lazy loaded from module `lazy-loaded-module-1`, and `lazy-loaded-module-1` is lazy loaded from `AppModule` Fixes angular/angular-cli#3663
b8158f0
to
9daed3e
Compare
@hans @filipesilva this PR is ready for review now. A few limitations that need to be addressed later: Nested Routes
|
This is one for @hansl to review, he's the one doing the brunt of the work on lazy loading in the CLI. |
This should be merged asap! My app is broken due to this issue and the fix proposed by @Meligy is working! Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Merged as 5d9cbd7 |
@Meligy please ensure that all commits are in the same PR. The PR you linked has not been reviewed by anyone and therefore has not been set for merge. Does this pose an issue that the commit in this PR has already been merged prior to the one in the other PR? Can it be merged later once it has been reviewed by someone on the core team? |
Hi @matsko, As mentioned in the description above, this PR builds on top of (and includes) the work from the other PR. The 2 commits can be applied in any order, and @hansl marked LGTM based on both commits (he asked me on the angular team slack to squash the commits, and accepted having them separate because they solve different -yet related- issues). So, you may cherry pick the commit from this branch or the other PR, and apply it later. It should still work just fine. Thanks a lot. |
Explanation:First, I worked on 1 commit that is the other PR #13676. Then I worked on this PR, and thought that because both issues are very related (but not dependent, only closely related), it might be easier to base my branch on the other PR and get a single approval -- this is what happened. This means the branch of this PR has 2 commits, as shown in this PR, and they are approved together. The PR could have been merged directly to master because it doesn't require an extra merge commit that would be undesirable in the commit log. Unfortunately what happened instead was cherry picking only one of the 2 commits in this PR. So, you can simply ignore the other PR and just look at the missing approved commit in this PR. It's the same change anyway. Sorry for the confusion, and I hope I have clarified things a bit better. |
@Meligy I'm sorry for the mistake. This was 100% my fault. I had done a I've merged your code into master. Thank you for following up on this. |
@matsko if this was cherry picked to master will this be in the next 2.* release? or will we need to wait for 4.0? |
fixes in 2.x |
It will show up in today's beta release of 4.0 and 2.4.3 (or tomorrow at the latest). |
Thank you :) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")
What is the current behavior? (You can also link to an open issue here)
If you have more than 3 levels of nested lazy routes, like:
{app-root}/lazy-loaded-module-1/lazy-loaded-module-2/lazy-loaded-module-3
Where
lazy-loaded-module-3
is lazy loaded fromlazy-loaded-module-2
,and
lazy-loaded-module-2
is lazy loaded from modulelazy-loaded-module-1
,and
lazy-loaded-module-1
is lazy loaded fromAppModule
You get only 2 chunk bundles created in addition to the main bundle, when you build your project using Angular CLI or @ng-tools Webpack plugin.
You'll be able to browse to
{app-root}/lazy-loaded-module-1/lazy-loaded-module-2/
but get a router error in browser for{app-root}/lazy-loaded-module-1/lazy-loaded-module-2/lazy-loaded-module-3
, because no bundle was generated for it.What is the new behavior?
Your build will include the same number of chunks as your lazy modules, plus the main chunk of course.
Your browser will be able to go to any level of nested lazy-loaded modules you declared.
Does this PR introduce a breaking change? (check one with "x")
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...Other information:
This PR includes work from PR #13676, and superseeds it.
The PR can be tested on this sample repository https://github.com/meligy/routing-angular-cli
The test path in this sample is
/lazy/deep/third/
. The UI walks you level by level as well.@hansl would be the best person to review this as he wrote the original implementation.
Fixes angular/angular-cli#3663