Skip to content

fix(core): resolve the tag name of dynamically created hosts - #71460

Open
aminesbdev wants to merge 1 commit into
angular:mainfrom
aminesbdev:fix/core-host-tag-name-dynamic-host
Open

aminesbdev wants to merge 1 commit into
angular:mainfrom
aminesbdev:fix/core-host-tag-name-dynamic-host

Conversation

@aminesbdev

@aminesbdev aminesbdev commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

HOST_TAG_NAME returns '#host' when the host isn't declared in a template: root components, components rendered by <router-outlet>, ViewContainerRef.createComponent, createComponent() (with or without hostElement and directives), and hosts created by TestBed.createComponent and TestBed.createDirective. The token returns tNode.value, and the host TNode built in ComponentFactory always holds the TNodeName.DynamicHost placeholder.

DebugElement.name has the same problem: it returns '#host' for the root of every fixture and for components rendered by <router-outlet>, NgComponentOutlet or ViewContainerRef.createComponent, so fixture.debugElement.query((de) => de.name === 'app-home') doesn't find a routed component.

Issue Number: Fixes #71459

What is the new behavior?

Both now go through a getElementTagName helper in view_utils.ts: when the TNode holds the placeholder, it reads the tag name from the native element, like resolveElement in sanitization.ts already does for host bindings. I went with localName so the value matches what a template gives: lowercase for HTML, original casing for SVG (foreignObject). It falls back to tagName for renderers whose elements don't have localName. Elements declared in templates don't go through this branch, so nothing changes for them.

The new tests in di_spec.ts cover a root component, skipSelf from an element in a root component's template, ViewContainerRef.createComponent with a host directive, createComponent() with a hostElement and directives, an SVG host and TestBed.createDirective. A test in debug_node_spec.ts checks DebugElement.name on a fixture root and finds a component created through a ViewContainerRef by name. All of them fail on main with Expected '#host' to be ....

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

One visible effect outside this repo: angular/components#30892 replaced element.tagName with HOST_TAG_NAME in MatChip. A chip created through createComponent or ViewContainerRef.createComponent gets a <mat-basic-chip> host (the first tag in its selector), so since that change it has been styled as a standard chip. With this fix it's a basic chip again, like it was before that PR.

@pullapprove
pullapprove Bot requested a review from atscott October 20, 2026 12:54
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Oct 20, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 20, 2026
@aminesbdev
aminesbdev force-pushed the fix/core-host-tag-name-dynamic-host branch from 7292a01 to 56962e4 Compare October 20, 2026 13:32
The host of a bootstrapped, routed or dynamically created component isn't declared in a template,
so its TNode holds the `#host` placeholder instead of a tag name. `HOST_TAG_NAME` and
`DebugElement.name` returned that placeholder as is. Both now read the tag name from the native
element in that case, like host binding sanitization already does for this placeholder.

Fixes angular#71459
@aminesbdev
aminesbdev force-pushed the fix/core-host-tag-name-dynamic-host branch from 56962e4 to 8e4f628 Compare October 20, 2026 14:11
@aminesbdev aminesbdev changed the title fix(core): resolve HOST_TAG_NAME for dynamically created hosts fix(core): resolve the tag name of dynamically created hosts Oct 20, 2026
@JeanMeche
JeanMeche requested a review from crisbeto October 20, 2026 18:17
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.

HOST_TAG_NAME and DebugElement.name return '#host' for bootstrapped, routed and dynamically created components

1 participant