fix(core): retain host element classes in createComponent#68910
Open
KirtiRamchandani wants to merge 1 commit into
Open
fix(core): retain host element classes in createComponent#68910KirtiRamchandani wants to merge 1 commit into
KirtiRamchandani wants to merge 1 commit into
Conversation
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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