Skip to content

fix(core): do not treat outputs named class or style as styling inputs - #71661

Merged
mattrbeck merged 2 commits into
angular:mainfrom
Flarette:fix/outputs-shadow-styling
Oct 28, 2026
Merged

mattrbeck merged 2 commits into
angular:mainfrom
Flarette:fix/outputs-shadow-styling

Conversation

@Flarette

Copy link
Copy Markdown
Contributor

Fixes #71660 | Regressed in #60036

Why the change

When a directive has an output named class or style, Angular sends the template's [class] or [style] value to directive inputs that don't exist, so the value is silently dropped. With this fix, only real inputs with those names take over the binding.

Special things to note

  • This is a regression from Input/output refactors #60036, first released in 19.2.0. That refactor moved the flag into per-binding helpers that both inputs and outputs share. Restoring the old code, which set the flag after collection by checking tNode.inputs, would also fix it. This fix keeps the helpers that Input/output refactors #60036 introduced and only sets the flag on the input path.
  • Inputs named class or style still take over the binding as before. A test covers a directive that has both an input and an output named class.
  • Apps with such an output will now see the bound classes or styles, which matches the behavior before 19.2.0.

Change outline

setShadowStylingInputFlags now runs only while inputs are being collected:

 initializeInputAndOutputAliases(tNode)
   for each directive on the node
     setupSelectorMatchedInputsOrOutputs(Inputs)
       setShadowStylingInputFlags          // input 'class' → hasClassInput
     setupSelectorMatchedInputsOrOutputs(Outputs)
-      setShadowStylingInputFlags          // output 'class' → hasClassInput too
     setupHostDirectiveInputsOrOutputs(Inputs)
       setShadowStylingInputFlags
     setupHostDirectiveInputsOrOutputs(Outputs)
-      setShadowStylingInputFlags

For a template binding, the flag decides where [class]="cls()" goes:

ɵɵclassMap(cls())
  if hasClassInput
    write to directive inputs named 'class'   ← an output alone left none, so the value was lost
  else
    apply the classes to the element

The tests in packages/core/test/acceptance/styling_spec.ts:

should not treat outputs named class or style as shadowing [class] and [style]   fails before the fix
should not treat a host directive output exposed as class as shadowing [class]   fails before the fix
should bind [class] as input to directive that also has an output named class    passes before and after

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

An output named class or style makes a template [class] or [style] binding on the same element do nothing. Interpolated class and style attributes are affected too, and so are host directives that expose such an output.

Issue Number: #71660

What is the new behavior?

These bindings are applied to the element. Only directive inputs named class or style take them over.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This is a candidate for the patch branch, because the regression dates back to 19.2.0.

When a directive had an output whose public name is `class` or `style`,
the node was flagged as having a directive input with that name. The
template's `[class]` or `[style]` binding was then sent to directive
inputs instead of the element, found none, and its value was silently
dropped. Interpolated `class`/`style` attributes and host directives
that expose such an output were affected as well.

The regression came from angular#60036, which moved the flag into helpers
shared by inputs and outputs. The flag is now set only while inputs
are collected, keeping the structure introduced by that refactor.
@pullapprove
pullapprove Bot requested a review from crisbeto October 27, 2026 14:19
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Oct 27, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 27, 2026
@Flarette

Copy link
Copy Markdown
Contributor Author

This regression first shipped in 19.2.0 (#60036), so the fix may also be a candidate for the patch branch. Could a maintainer consider adding the target: patch label?

…g inputs

Add a test that a `(class)` listener still receives events from an
output named `class` while `[class]` is bound on the same element.
@JeanMeche JeanMeche added target: patch This PR is targeted for the next patch release action: global presubmit The PR is in need of a google3 global presubmit labels Oct 27, 2026
@JeanMeche
JeanMeche removed the request for review from crisbeto October 27, 2026 18:18
@JeanMeche JeanMeche added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Oct 28, 2026
@JeanMeche

Copy link
Copy Markdown
Member
@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Oct 28, 2026
@mattrbeck mattrbeck removed the target: patch This PR is targeted for the next patch release label Oct 28, 2026
@mattrbeck
mattrbeck merged commit 5fb2b68 into angular:main Oct 28, 2026
33 checks passed
@mattrbeck

Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: global presubmit The PR is in need of a google3 global presubmit action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: minor This PR is targeted for the next minor release

3 participants