bug(CdkPortalOutlet): Component can be rendered outside CdkPortalOutlet
- Dominant language
- TypeScript
- Stars
- 25k
- Forks
- 6.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 91
Description
### Is this a regression?
- [ ] Yes, this behavior used to work in the previous version
### The previous version in which this bug was not present was
_No response_
### Description
If you have ComponentPortal with provided ViewContainerRef NgForOf can rerender component outside CdkPortalOutlet.
Looks like [this code](https://github.com/angular/components/blob/7a24e95bafbdeb697f74a48e275c2442bcbefc74/src/cdk/portal/portal-directives.ts#L166) is executed only once and after NgForOf dom manipulations there is nothing that can move ComponentPortalExample to expected position
### Reproduction
[Demo](https://stackblitz.com/edit/angular-ivy-lthq8f?file=src%2Fapp%2Fportal.component.ts,src%2Fapp%2Fapp.module.ts,src%2Fapp%2Fapp.component.html)
Steps to reproduce:
1. Wait until component outlet will render component
2. Drag Item 1 down
3. Drag Item 1 up
4. ComponentPortalExample is rendered inside item list instead of inside component outlet
instead
### Expected Behavior
ComponentPortalExample should stay inside CdkPortalOutlet
### Actual Behavior
ComponentPortalExample is rendered inside item list instead of inside CdkPortalOutlet
### Environment

Contributor guide
Research direction
Start with src/cdk/portal/portal-directives.ts at the linked code and reproduce the issue using the provided StackBlitz demo. Investigate the interaction between ComponentPortal, the provided ViewContainerRef, and NgForOf DOM reordering; done means ComponentPortalExample remains inside CdkPortalOutlet after dragging Item 1 down and back up.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100