Skip to content

fix(core): retain host element classes in createComponent#68910

Open
KirtiRamchandani wants to merge 1 commit into
angular:mainfrom
KirtiRamchandani:fix/retain-root-host-classes
Open

fix(core): retain host element classes in createComponent#68910
KirtiRamchandani wants to merge 1 commit into
angular:mainfrom
KirtiRamchandani:fix/retain-root-host-classes

Conversation

@KirtiRamchandani
Copy link
Copy Markdown

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 TAttributes with the placeholder ng-version attribute. Static host classes were later written as the full class attribute, 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 TAttributes before 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.ts
  • git diff --check
  • In a native WSL/Linux clone: corepack pnpm bazel test //packages/core/test/acceptance:acceptance --test_arg=--filter='should retain classes from an existing host element' --test_output=errors
  • Verified the new regression test fails against the previous implementation when only the runtime file is restored.

@pullapprove pullapprove Bot requested a review from JeanMeche May 25, 2026 02:35
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label May 25, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues related to the framework runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

class names are not retained when host is used with Component decorator

1 participant