You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RouteConfigLoadStart event not firing if the navigation of a lazy loaded route was previously canceled #44577
Which @angular/* package(s) are the source of the bug?
router
Is this a regression?
No
Description
If the navigation of a lazy loaded route was previously canceled, the RouteConfigLoadStart event is never fired again, although the RouteConfigLoadEnd fires.
It seams that the loader that contains the observable is returned immediately without triggering the RouteConfigLoadStart. This invalidates the possibility to track the loading progress of a route when the navigation is canceled and resumed sometime in the future (see code below).
I am not sure how I can provide a reproduction for this since the loading of the route is network dependent, but I think that by looking at the code below, is easy to understand the problem.
This really does need a reproduction. The intent was to clear the loader if it was unsuccessful but this would not happen if it completes without an error
I'm not sure exactly how that would happen, but this appears as though it could be the issue.
That said, the ordering of the event is correct and the fact that it's not called if _loader$ already exists is also correct. The preloader and a navigation can both request a lazy loaded route to be loaded at the same time. The code prevents double loading and double listener notification. onLoadStartListener should not be called twice in this case.
I am not sure how I can reproduce this but before I attempt to do so, let me present you the scenario that I am facing so you can tell me if this is the expected behavior or not. If it's not I will then try to provide a reproduction.
Imagine that I have 2 routes: \a and \b: \a is lazy loaded; \b it's not lazy loaded;
First I navigate to \a but when the bundle chunk starts to download I quickly change my mind and go to \b. When logging the router events I get this sequence:
\a
NavigationStart
RouteConfigLoadStart
NavigationCancel
\b
NavigationStart
RoutesRecognized
GuardsCheckStart
ChildActivationStart
...
NavigationEnd
After that if I decide to go back to \a, I get the following events:
\a
NavigationStart
RouteConfigLoadEnd
RoutesRecognized
GuardsCheckStart
ChildActivationStart
...
NavigationEnd
As you can see in my latest navigation to \a I don't receive the RouteConfigLoadStart even though the chunk may or may not be still being downloaded. This prevents me from relying in this two events to track the load progress since I can't know in the last navigation to \a if the chunk is already downloaded or not. The only thing that I get to know is when the Load has finished but there is no way to know if it is still in progress prior to that. Maybe there should be a RouteConfigLoadResumed event or something? This may sound a bit "picky" but I would like to hear your thoughts on this.
I see... So it's not actually that the loading is canceled. It is started once on the initial navigation and then completes by the time the third navigation comes around. This would be the same issue as with the preloading example. I don't think RouteConfigLoadStart is necessarily the correct event and RouteConfigLoadResumed doesn't feel quite right either since the loading was never paused.
There is a common theme for several open issues around lazy loading and the lack of public information and configurability. I'm going to categorize this as a feature request that should be looked at along with those.
related: #24069, #16282, #40010. If we had a simple helper function to return the @internal_loadedConfig property, you could use NavigationStart and check if the route has a loadChildren and doesn't yet have the loaded config to determine if it is yet to be loaded during the navigation.
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.
You can find more details about the feature request process in our documentation.
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
Activity
Carlosamouco commentedon Dec 29, 2021
Can the
onLoadStartListenerrun before theroute._loader$is returned?atscott commentedon Jan 4, 2022
This really does need a reproduction. The intent was to clear the loader if it was unsuccessful but this would not happen if it completes without an error
angular/packages/router/src/router_config_loader.ts
Lines 60 to 63 in 8ebc946
I'm not sure exactly how that would happen, but this appears as though it could be the issue.
That said, the ordering of the event is correct and the fact that it's not called if
_loader$already exists is also correct. The preloader and a navigation can both request a lazy loaded route to be loaded at the same time. The code prevents double loading and double listener notification.onLoadStartListenershould not be called twice in this case.Carlosamouco commentedon Jan 5, 2022
I am not sure how I can reproduce this but before I attempt to do so, let me present you the scenario that I am facing so you can tell me if this is the expected behavior or not. If it's not I will then try to provide a reproduction.
Imagine that I have 2 routes:
\aand\b:\ais lazy loaded;\bit's not lazy loaded;First I navigate to
\abut when the bundle chunk starts to download I quickly change my mind and go to\b. When logging the router events I get this sequence:\a\bAfter that if I decide to go back to
\a, I get the following events:\aAs you can see in my latest navigation to
\aI don't receive theRouteConfigLoadStarteven though the chunk may or may not be still being downloaded. This prevents me from relying in this two events to track the load progress since I can't know in the last navigation to\aif the chunk is already downloaded or not. The only thing that I get to know is when the Load has finished but there is no way to know if it is still in progress prior to that. Maybe there should be aRouteConfigLoadResumedevent or something? This may sound a bit "picky" but I would like to hear your thoughts on this.atscott commentedon Jan 5, 2022
I see... So it's not actually that the loading is canceled. It is started once on the initial navigation and then completes by the time the third navigation comes around. This would be the same issue as with the preloading example. I don't think
RouteConfigLoadStartis necessarily the correct event andRouteConfigLoadResumeddoesn't feel quite right either since the loading was never paused.There is a common theme for several open issues around lazy loading and the lack of public information and configurability. I'm going to categorize this as a feature request that should be looked at along with those.
related: #24069, #16282, #40010. If we had a simple helper function to return the
@internal_loadedConfigproperty, you could useNavigationStartand check if the route has aloadChildrenand doesn't yet have the loaded config to determine if it is yet to be loaded during the navigation.Carlosamouco commentedon Jan 5, 2022
Thank you @atscott, that would solve the problem.
angular-robot commentedon Jan 6, 2022
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.
You can find more details about the feature request process in our documentation.
angular-robot commentedon Feb 14, 2022
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.
Find more details about Angular's feature request process in our documentation.
angular-robot commentedon Mar 6, 2022
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
atscott commentedon Oct 3, 2022
Closing as duplicate of #31800 and #40010 in spirit
angular-automatic-lock-bot commentedon Nov 3, 2022
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.