Skip to content

fix(router): avoid router initialization for non root components #12338

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

Closed
wants to merge 1 commit into from
Closed

fix(router): avoid router initialization for non root components #12338

wants to merge 1 commit into from

Conversation

mseemann
Copy link
Contributor

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?
If more than one component is bootstrapped the router is initialized more than once. see issues:

What is the new behavior?

  • if additional components are bootstrapped the router is not initialized again

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[x] No

Other information:
@vsavkin This pr only solves the mentioned issues. I'm not quite sure. But I think a more general solution would be to make sure the listener for APP_BOOTSTRAP_LISTENER is only called once.

// register a spy on a function that is called on each init
const spy = spyOn(r, 'resetRootComponentType').and.callThrough();

// bootstrap the root app
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the comments? I think it is pretty clear what the test does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

spy.calls.reset();

// bootstrap a component that is not the root compnent
appRef.bootstrap(BootstrappableComponent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bootstrap method returns a component ref that can be destroyed. Could you make sure it works when the first component is destroyed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

this works because the destroyed component is removed from ApplicationRef.components and the next bootstrapped component is at index 0 of ApplicationRef.components. I have added a test for this.

@vsavkin vsavkin added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Nov 2, 2016
@mseemann
Copy link
Contributor Author

mseemann commented Nov 2, 2016

@vsavkin all done. the travis build fails because of invalid saucelab configurations :(

@vicb
Copy link
Contributor

vicb commented Nov 10, 2016

Could you please squash & rebase ?

@mseemann
Copy link
Contributor Author

@vicb done.

@vicb vicb added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Nov 11, 2016
@vicb
Copy link
Contributor

vicb commented Nov 11, 2016

Thanks, should be merged today.

vicb pushed a commit to vicb/angular that referenced this pull request Nov 11, 2016
@vicb vicb closed this in 2a4bf9a Nov 11, 2016
@mseemann mseemann deleted the fix_router_initialization branch November 11, 2016 20:04
@angular-automatic-lock-bot
Copy link

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 Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: router cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants