Skip to content

Commit

Permalink
refactor(compiler): Don't emit class and style bindings on structural…
Browse files Browse the repository at this point in the history
… template views

The Template Pipeline has had a number of tricky bugs involving bindings on structural elements.

Consider this template:

```
<div *ngIf="true" [class.bar]="field"></div>
```

We were incorrectly emitting `ɵɵclassProp` on *both* the template's view, and the inner view. The solution is to just emit an extracted attribute on the enclosing template, so it still shows up in the const array, but does not affect the update block.

We should look to refactor binding ingestion soon.
  • Loading branch information
dylhunn committed Dec 8, 2023
1 parent 95099d4 commit ecff426
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
"class_binding_on_structural.js"
]
}
],
"skipForTemplatePipeline": true
]
}
]
}
3 changes: 2 additions & 1 deletion packages/compiler/src/template/pipeline/src/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ function ingestBinding(
}

if (flags & BindingFlags.OnNgTemplateElement && !(flags & BindingFlags.BindingTargetsTemplate) &&
type === e.BindingType.Property) {
(type === e.BindingType.Property || type === e.BindingType.Class ||
type === e.BindingType.Style)) {
// This binding only exists for later const extraction, and is not an actual binding to be
// created.
view.create.push(ir.createExtractedAttributeOp(
Expand Down

0 comments on commit ecff426

Please sign in to comment.