-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
perf(angular): views are not moved on mount #28544
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, verified that it fixes the issue. Suggestions given.
cmpRef = this.activated = this.location.createComponent(component, { | ||
index: this.location.length, | ||
/** | ||
* View components need to be added as a child of ion-router-outlet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it mention that it needs to be added as a child due to animations? It could make it easier for future debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Added in d32f66e
packages/angular/src/directives/navigation/ion-router-outlet.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Maria Hutt <[email protected]>
Co-authored-by: Maria Hutt <[email protected]>
Issue number: resolves #28534
What is the current behavior?
Page views in Ionic need to be rendered as a child of
ion-router-outlet
in order for page transitions and swipe to go back to function correctly. However, Angular always inserts components as siblings of the insertion point. Previously, the insertion point wasion-router-outlet
(the host element). This meant that page views were mounted as siblings ofion-router-outlet
. We then added code to move the component inside ofion-router-outlet
.This caused two issues:
connectedCallback
fired twice. This callback runs when the component is added to the DOM. On initial mount,connectedCallback
for each component runs. Once the page view is moved, the elements are removed from the DOM (thus causingdisconnectedCallback
to run), and then added to the correct location in the DOM which causesconnectedCallback
to run again.What is the new behavior?
ng-container
. This appears as a comment in the DOM inside ofion-router-outlet
. This comment is used as the injection point for adding new views. The new views are added as siblings of the comment, but since the comment is inside ofion-router-outlet
then the views themselves are inside ofion-router-outlet
too.Does this introduce a breaking change?
This doesn't cause any known breaking changes. However, the placement of views is pretty critical to the functionality of Ionic, so I wanted to ship this in a major release so we have a solid public testing period before the code is considered stable.
We already have test coverage that verifies page views are mounted in the correct order, so I did not add more tests for this.
Other information
Dev build: 7.6.2-dev.11704390532.1202188d
Testing:
npm run dev:ssr
.npm run dev:ssr
. Observe that the error noted in the original issue does not appear.Note: The Angular SSR package does not support Web Components. As a result, there are other errors you will encounter. However, I still think it's worth fixing this issue a) in the event that the Angular SSR package adds support for Web Components and b) to get the performance gain of not having to re-mount components.