The Wayback Machine - https://web.archive.org/web/20210828032122/https://github.com/angular/angular/pull/42560
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

fix(router): error if module is destroyed before location is initialized #42560

Closed
wants to merge 1 commit into from

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Jun 12, 2021

This is something I ran into while working on a fix for the TestBed module teardown behavior for #18831. In the RouterInitializer.appInitializer we have a callback to the LOCATION_INITIALIZED which has to do some DI lookups. The problem is that if the module is destroyed before the location promise resolves, the Injector.get calls will fail. This is unlikely to happen in a real app, but it'll show up in unit tests once the test module teardown behavior is fixed.

if (this.destroyed) {
return Promise.resolve(true);
}

This comment has been minimized.

@crisbeto

crisbeto Jun 12, 2021
Author Member

Another way of solving this would be to pull the injector.get calls outside of the callback. I decided against it, because I wasn't sure if the Router and RouterConfiguration would be available earlier in the lifecycle.

This is something I ran into while working on a fix for the `TestBed` module teardown behavior for #18831. In the `RouterInitializer.appInitializer` we have a callback to the `LOCATION_INITIALIZED` which has to do some DI lookups. The problem is that if the module is destroyed before the location promise resolves, the `Injector.get` calls will fail. This is unlikely to happen in a real app, but it'll show up in unit tests once the test module teardown behavior is fixed.
@crisbeto crisbeto force-pushed the crisbeto:router-init-error branch from 535689d to 853d031 Jun 12, 2021
@crisbeto crisbeto marked this pull request as ready for review Jun 12, 2021
@pullapprove pullapprove bot requested a review from atscott Jun 12, 2021
@atscott
Copy link
Contributor

@atscott atscott commented Jun 14, 2021

dylhunn added a commit that referenced this pull request Jun 17, 2021
…zed (#42560)

This is something I ran into while working on a fix for the `TestBed` module teardown behavior for #18831. In the `RouterInitializer.appInitializer` we have a callback to the `LOCATION_INITIALIZED` which has to do some DI lookups. The problem is that if the module is destroyed before the location promise resolves, the `Injector.get` calls will fail. This is unlikely to happen in a real app, but it'll show up in unit tests once the test module teardown behavior is fixed.

PR Close #42560
@dylhunn dylhunn closed this in 07c1ddc Jun 17, 2021
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Jul 18, 2021

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants