Skip to content

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

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

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

Conversation

@KirtiRamchandani

Copy link
Copy Markdown
Contributor

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
Preserve existing host element classes when createComponent attaches host bindings to a supplied element.
@KirtiRamchandani
KirtiRamchandani force-pushed the fix/retain-root-host-classes branch from b131547 to 9355333 Compare June 5, 2026 05:49
@KirtiRamchandani

Copy link
Copy Markdown
Contributor Author

Pushed an update on this PR branch at 9355333. This fixes the two CI issues from the previous run:

  • amended the commit message with a body so
    g-dev pullapprove verify has the required 20+ character body
  • updated the affected core bundling �undle.golden_symbols.json files for the host-class parsing symbols reported by symbol_test

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.

@JeanMeche

Copy link
Copy Markdown
Member

This is a change of behavior that could be somehow breaking. We'll wait for more feedback before we potentially land it.

@angular-automatic-lock-bot

Copy link
Copy Markdown

This pull request has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Oct 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

2 participants