Skip to content

fix(migrations): handle reused templates in control flow migration#63996

Closed
aparzi wants to merge 1 commit intoangular:mainfrom
aparzi:fix-migration-control-flow
Closed

fix(migrations): handle reused templates in control flow migration#63996
aparzi wants to merge 1 commit intoangular:mainfrom
aparzi:fix-migration-control-flow

Conversation

@aparzi
Copy link
Contributor

@aparzi aparzi commented Sep 22, 2025

The control flow migration was incorrectly removing ng-template elements in scenarios where they were referenced by multiple *ngIf directives' else clauses and also used independently via ngTemplateOutlet.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Template:

<div *ngIf="1 == 1; else elseTemplate">
  <h1>TEST</h1>
</div>
<div *ngIf="1 == 1; else elseTemplate">
  <h1>TEST</h1>
</div>

<ng-container [ngTemplateOutlet]="elseTemplate"></ng-container>
<ng-template #elseTemplate>
  <h1>Test</h1>
  <div>Test</div>
</ng-template>

After:

@if (1==1) {
  <div>
    <h1>TEST</h1>
  </div>
} @else {
  <h1>Test</h1>
  <div>Test</div>
}

@if (1==1) {
  <div>
    <h1>TEST</h1>
  </div>
} @else {
  <h1>Test</h1>
  <div>Test</div>
}
<ng-container [ngTemplateOutlet]="elseTemplate"></ng-container>

What is the new behavior?

This change updates the template processing logic to correctly detect all usages of a template, including property-bound [ngTemplateOutlet]. The migration will now preserve the ng-template if it's still referenced after the *ngIf directives have been migrated.

Now:

@if (1 == 1) {
<div><h1>TEST</h1></div>
} @else {
<h1>Test</h1>
<div>Test</div>
} @if (1 == 1) {
<div><h1>TEST</h1></div>
} @else {
<h1>Test</h1>
<div>Test</div>
} <ng-container [ngTemplateOutlet]="elseTemplate"></ng-container>
<ng-template #elseTemplate>
  <h1>Test</h1>
  <div>Test</div>
</ng-template>

Does this PR introduce a breaking change?

  • Yes
  • No

@pullapprove pullapprove bot requested a review from mmalerba September 22, 2025 20:43
@angular-robot angular-robot bot added the area: migrations Issues related to `ng update`/`ng generate` migrations label Sep 22, 2025
@ngbot ngbot bot added this to the Backlog milestone Sep 22, 2025
@aparzi aparzi force-pushed the fix-migration-control-flow branch from c378836 to 9301b7f Compare September 22, 2025 21:24
@aparzi aparzi force-pushed the fix-migration-control-flow branch from 9301b7f to 434c0c9 Compare September 23, 2025 21:48
@aparzi aparzi requested a review from JeanMeche September 23, 2025 21:48
The control flow migration was incorrectly removing `ng-template` elements in scenarios where they were referenced by multiple `*ngIf` directives' `else` clauses and also used independently via `ngTemplateOutlet`.
@aparzi aparzi force-pushed the fix-migration-control-flow branch from 434c0c9 to 244a4ac Compare September 23, 2025 22:22
@aparzi aparzi requested a review from JeanMeche September 23, 2025 22:22
@thePunderWoman thePunderWoman removed the request for review from mmalerba September 24, 2025 15:10
@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Sep 24, 2025
@thePunderWoman
Copy link
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

thePunderWoman pushed a commit that referenced this pull request Sep 24, 2025
…63996)

The control flow migration was incorrectly removing `ng-template` elements in scenarios where they were referenced by multiple `*ngIf` directives' `else` clauses and also used independently via `ngTemplateOutlet`.

PR Close #63996
@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 Oct 25, 2025
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: migrations Issues related to `ng update`/`ng generate` migrations target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants