Repository navigation
fix(core): retain host element classes in createComponent - #68910
Closed
KirtiRamchandani wants to merge 1 commit into
Closed
KirtiRamchandani wants to merge 1 commit into
KirtiRamchandani wants to merge 1 commit into
Conversation
Preserve existing host element classes when createComponent attaches host bindings to a supplied element.
KirtiRamchandani
force-pushed
the
fix/retain-root-host-classes
branch
from
June 5, 2026 05:49
b131547 to
9355333
Compare
Contributor
Author
|
Pushed an update on this PR branch at 9355333. This fixes the two CI issues from the previous run:
Local checks run here: parsed the updated JSON goldens and git diff --check HEAD~1..HEAD. I did not run the full Bazel suite locally; the GitHub Actions run has restarted on the new head. |
Member
|
This is a change of behavior that could be somehow breaking. We'll wait for more feedback before we potentially land it. |
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
createComponent(..., {hostElement})replaces classes that already exist on the provided host element when the component also declares static host classes.Fixes #51460.
Root cause
For existing root host elements, Angular only seeded the root
TAttributeswith the placeholderng-versionattribute. Static host classes were later written as the fullclassattribute, so classes that were already present on the host element were not part of the static styling data and were overwritten.Solution
Read the existing host element class list after locating the root host, parse it with Angular's class parser, and include those classes in the root
TAttributesbefore static host styling is computed. This keeps existing host classes and component/directive static host classes in the same styling merge path.Tests
npx --yes prettier@3.8.3 --check packages/core/src/render3/component_ref.ts packages/core/test/acceptance/create_component_spec.tsgit diff --checkcorepack pnpm bazel test //packages/core/test/acceptance:acceptance --test_arg=--filter='should retain classes from an existing host element' --test_output=errors