Skip to content

fix(cdk/portal): run change detection before inserting portal content #20346

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crisbeto
Copy link
Member

In #16407 we made some changes where we'd run change detection after transferring the portal content to the outlet, in order to handle a case where focus traps may be attached too early. This PR reverts back to triggering change detection before moving the content, because doing it after may leave behind nodes that were inserted through ViewContainerRef inside one one of the init hooks. The initial focus trap issue is resolved by delaying the attachment instead.

These changes fix another issue where we were assuming that component portals can only have one root node. This is true for most cases, except for when a sibling is inserted through ViewContainerRef.

Finally, these changes add a detectChanges call before moving the contents of a component portal for consistency between portals. Previously we were only doing in for template portals.

Fixes #20343.

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release labels Aug 17, 2020
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 17, 2020
@crisbeto crisbeto marked this pull request as draft August 17, 2020 21:31
@crisbeto crisbeto marked this pull request as ready for review August 17, 2020 22:10
@crisbeto crisbeto changed the title fix(portal): run change detection before inserting portal content fix(cdk/portal): run change detection before inserting portal content Oct 15, 2020
@devversion devversion removed their request for review August 18, 2021 12:58
@crisbeto crisbeto requested a review from a team as a code owner September 6, 2021 19:43
In angular#16407 we made some changes where we'd run change detection after transferring the
portal content to the outlet, in order to handle a case where focus traps may be attached
too early. This PR reverts back to triggering change detection before moving the content,
because doing it after may leave behind nodes that were inserted through
`ViewContainerRef` inside one one of the init hooks. The initial focus trap issue is resolved
by delaying the attachment instead.

These changes fix another issue where we were assuming that component portals can only have one
root node. This is true for most cases, except for when a sibling is inserted through `ViewContainerRef`.

Fixes angular#20343.
@josephperrott josephperrott removed the request for review from a team September 7, 2021 16:05
@andrewseguin andrewseguin removed the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 28, 2021
@josephperrott josephperrott added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed needs rebase labels Nov 16, 2022
@andrewseguin andrewseguin assigned amysorto and unassigned devversion and amysorto Jun 5, 2023
@josephperrott josephperrott requested a review from a team as a code owner December 18, 2024 17:40
@josephperrott josephperrott requested review from amysorto and removed request for a team December 18, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(Overlay): ViewContainerRef.createComponent() fails within Overlay
7 participants