Skip to content

RouteConfigLoadStart event not firing if the navigation of a lazy loaded route was previously canceled #44577

Closed as not planned

Description

@Carlosamouco

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.

router_config_loader.ts

load(parentInjector: Injector, route: Route): Observable<LoadedRouterConfig> {
    if (route._loader$) {
      return route._loader$;
    }

    if (this.onLoadStartListener) {
      this.onLoadStartListener(route);
    }
...

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 13.1.2
Node: 12.22.2
Package Manager: npm 6.14.13
OS: win32 x64

Angular: 13.1.1
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1301.2
@angular-devkit/build-angular   13.1.2
@angular-devkit/core            13.1.2
@angular-devkit/schematics      13.1.2
@angular/cli                    13.1.2
@schematics/angular             13.1.2
ng-packagr                      13.0.8
rxjs                            7.4.0
typescript                      4.4.4

Anything else?

No response

Activity

  1. Carlosamouco commented on Dec 29, 2021

    @Carlosamouco
    ContributorAuthor

    Can the onLoadStartListener run before the route._loader$ is returned?

  2. added this to the needsTriage milestone on Jan 4, 2022
  3. atscott commented on Jan 4, 2022

    @atscott
    Contributor

    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

    catchError((err) => {
    route._loader$ = undefined;
    throw err;
    }),

    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.

  4. added
    needs reproduction
    P3
    on Jan 4, 2022
  5. modified the milestones: needsTriage, Backlog on Jan 4, 2022
  6. Carlosamouco commented on Jan 5, 2022

    @Carlosamouco
    ContributorAuthor

    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.

  7. added
    feature
    and removed
    needs reproduction
    P3
    on Jan 5, 2022
  8. atscott commented on Jan 5, 2022

    @atscott
    Contributor

    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.

  9. Carlosamouco commented on Jan 5, 2022

    @Carlosamouco
    ContributorAuthor

    Thank you @atscott, that would solve the problem.

  10. angular-robot commented on Jan 6, 2022

    @angular-robot
    Contributor

    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.

  11. angular-robot commented on Feb 14, 2022

    @angular-robot
    Contributor

    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.

  12. angular-robot commented on Mar 6, 2022

    @angular-robot
    Contributor

    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.

  13. atscott commented on Oct 3, 2022

    @atscott
    Contributor

    Closing as duplicate of #31800 and #40010 in spirit

  14. angular-automatic-lock-bot commented on Nov 3, 2022

    @angular-automatic-lock-bot

    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.

  15. locked and limited conversation to collaborators on Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerfeaturerouter: lazy loading

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions