question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router 3.2.0 - Providers instantiated twice

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior After upgrading to router 3.2.0, services being provided by component module are being instantiated twice. Once while resolver is being run (last place in router is PreActivation.prototype.getToken) and then again later during activation (last place in router is RouterOutlet.prototype.activate). Upgrading rest of Angular to 2.2.0 and leaving router at 3.1.1 it works as it used to (and looking in debugger I see service is only instantiated from PreActivation.prototype.getToken)

Expected behavior

Providers should only be instantiated once - as they are when using router version 3.1.1

Minimal reproduction of the problem with instructions

Haven’t yet reproduced in a plnkr but my use case has a lazy loaded component that itself has sub components (not lazy loaded). The sub component has a resolver that uses a service, and the sub component itself uses the service. The service is included in the lazy loaded components module providers list and is being instantiated twice. Once apparently while router is working on resolve and once when component is being activated.

What is the motivation / use case for changing the behavior?

Its just wrong, and my service fetches data on initialization so extra instance causes extra fetch. This does not happen with router 3.1.1 (never tried 3.1.2 as deactivate guards don’t work correctly in that version)

Please tell us about your environment:

Windows 10, Visual Studio Code, angular-cli: 1.0.0-beta.19-3 ng serve

  • Angular version: 2.0.X

2.2.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

Only tried in Chrome

  • Language: [all | TypeScript X.X | ES6/7 | ES5] Typescript 2.0.9

  • Node (for AoT issues): node --version =

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:32
  • Comments:77 (20 by maintainers)

github_iconTop GitHub Comments

35reactions
mheverycommented, Feb 28, 2017

Just an FYI, @vicb is working on this issue now. We are cautiously optimistic, about it making into v4.0.0

25reactions
robwormaldcommented, Jan 20, 2017

Update: we had a discussion / design review today on this, and think we have a workable solution to solve it. Just verifying the semantics are right and we’ll land a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with angular2 router' resolve being executed twice
I have got an issue with my configuration of angular2 router's Routes whereby a resolve is executed twice although defined only once.
Read more >
Issue with angular2 router' resolve being executed twice ...
Could be related to Router 3.2.0 - Providers instantiated twice. Try downgrading @angular/router to ~3.1.0. Tzach Ovadia 1168. score:1.
Read more >
Angular on Twitter: "Just released Angular 2.4.2! All bug fixes for ...
Router 3.2.0 - Providers instantiated twice · Issue #12869 · angular/angular. I'm submitting a ... (check one with "x") [x] bug report =>...
Read more >
IP Routing: BGP Configuration Guide - Connecting to a ... - Cisco
IP Routing: BGP Configuration Guide -Connecting to a Service Provider ... modified to add the local autonomous system number 40000 twice.
Read more >
NgOnInit called on every route change - Ionic Angular
Hello everyone, I have a problem with routing in my app. I tought that in Ionic on every route change, components are not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found