Repository navigation
Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
Which @angular/* package(s) are the source of the bug?
core, compiler
Is this a regression?
Not sure
Description
A component created through ViewContainerRef.createComponent() gets its host element in the SVG namespace when the ViewContainerRef belongs to the root element of an @if block that comes directly after an element ending with an <svg>. The host element is an SVGElement inside an HTML tree, so the browser does not render it at all.
Real-world impact: in MatPaginator with showFirstLastButtons, the tooltip of the "Last page" button never appears. You can see this in the official "Configurable paginator" example on https://material.angular.dev/components/paginator/examples (v22.3.0). The overlay pane is created, but <mat-tooltip-component> is an SVGElement (namespaceURI === 'http://www.w3.org/2000/svg'), so the pane is 0×0 px. The tooltips of "First page", "Previous page" and "Next page" are created in the XHTML namespace and work.
Root cause:
- The compiler emits
ɵɵnamespaceSVG()/ɵɵnamespaceHTML()only before element start instructions (namespace phase of the template pipeline). Container instructions such asɵɵconditionalCreatedo not get a namespace instruction before them. ɵɵelementEnd()does not reset the current namespace. After<button><svg>…</svg></button>,currentNamespaceis stillsvg.- In the paginator template, the
@if (showFirstLastButtons)block with the "Last page" button comes directly after the "Next page" button, whose last child is an<svg>. The container TNode of that@ifis created bycreateTNodewithnamespace: getNamespace(), so it storessvg, a leftover value that does not describe any real element. - The "Last page" button itself is created correctly as HTML, because every embedded view starts with a clean
currentNamespace. MatTooltipcreatesTooltipComponentthrough the button'sViewContainerRef.R3ViewContainerRef._getHostElementNamespace()takes the namespace of the host TNode's parent. For the root element of an embedded view, that parent is the@ifcontainer TNode (_hostLView[T_HOST]), so it returnssvg.createHostElement()then callsrenderer.createElement('mat-tooltip-component', 'svg').
The "First page" button is not affected: its @if block comes before any <svg>, so its container TNode stores null (HTML).
Please provide a link to a minimal reproduction of the bug
Minimal reproduction without Angular Material:
StackBlitz: https://stackblitz.com/edit/stackblitz-starters-wyfwacmf?file=src%2Fmain.ts
import { Component, Directive, OnInit, ViewContainerRef, inject, input } from '@angular/core';
@Component({
selector: 'app-probe',
template: 'probe',
})
export class Probe {}
@Directive({ selector: '[createProbe]' })
export class CreateProbe implements OnInit {
public readonly createProbe = input.required<string>();
private readonly vcr = inject(ViewContainerRef);
public ngOnInit(): void {
const ref = this.vcr.createComponent(Probe);
console.warn(this.createProbe(), (ref.location.nativeElement as Element).namespaceURI);
}
}
@Component({
selector: 'app-root',
imports: [CreateProbe],
template: `
<div>
@if (true) {
<span createProbe="A">A</span>
}
<button><svg viewBox="0 0 24 24"><path d="M0 0h24v24H0z" /></svg></button>
@if (true) {
<span createProbe="B">B</span>
}
</div>
`,
})
export class App {}Expected: both A and B log http://www.w3.org/1999/xhtml, and both "probe" texts are rendered.
Actual: A logs http://www.w3.org/1999/xhtml. B logs http://www.w3.org/2000/svg, and its "probe" text is not rendered.
Please provide the exception or error you saw
No error. The dynamically created host element silently ends up in the SVG namespace.
Please provide the environment you discovered this bug in (run ng version)
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI : 22.2.0
Angular : 22.2.0
Node.js : 24.21.0
Package Manager : npm 11.19.0
Operating System : win32 x64
┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/core │ 22.2.0 │ ^22.2.0 │
│ @angular/animations │ 22.2.0 │ ^22.2.0 │
│ @angular/build │ 22.2.0 │ ^22.2.0 │
│ @angular/cdk │ 22.2.0 │ ^22.2.0 │
│ @angular/cli │ 22.2.0 │ ^22.2.0 │
│ @angular/common │ 22.2.0 │ ^22.2.0 │
│ @angular/compiler │ 22.2.0 │ ^22.2.0 │
│ @angular/compiler-cli │ 22.2.0 │ ^22.2.0 │
│ @angular/core │ 22.2.0 │ ^22.2.0 │
│ @angular/forms │ 22.2.0 │ ^22.2.0 │
│ @angular/language-service │ 22.2.0 │ ^22.2.0 │
│ @angular/material │ 22.2.0 │ ^22.2.0 │
│ @angular/material-moment-adapter │ 22.2.0 │ ^22.2.0 │
│ @angular/platform-browser │ 22.2.0 │ ^22.2.0 │
│ @angular/platform-browser-dynamic │ 22.2.0 │ ^22.2.0 │
│ @angular/router │ 22.2.0 │ ^22.2.0 │
│ @schematics/angular │ 22.2.0 │ ^22.2.0 │
│ rxjs │ 7.8.2 │ ^7.8.0 │
│ typescript │ 6.0.3 │ ^6.0.3 │
│ zone.js │ 0.15.1 │ ^0.15.1 │
└───────────────────────────────────┴───────────────────┴───────────────────┘
Seen with @angular/core 22.2.0 and @angular/material 22.2.0. Also reproducible on material.angular.dev (22.3.0), in a Chromium-based browser.
Anything else?
Possible fixes:
- Compiler: emit the namespace instruction before container-creating instructions (
ɵɵconditionalCreate,ɵɵconditionalBranchCreate,ɵɵtemplate,ɵɵrepeaterCreate), so the container TNode records the namespace of its enclosing element rather than a leftover value. - Runtime: in
_getHostElementNamespace(), when the parent TNode is a container, walk up to the nearest element TNode and use its namespace instead of the container'snamespace. The existingforeignObjectcheck shows the namespace is meant to come from a real enclosing element.
Reproduction
StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-wyfwacmf?file=src%2Fmain.ts
Steps to reproduce:
- Run
Expected Behavior
The element should render in xhtml namespace and should be visible
Actual Behavior
The element renders in svg namespace and it's not visible
Environment
- Angular: 22.2.0
- CDK/Material: 22.2.0
- Browser(s): Chrome Version 158.0.8127.88 (Official Build) (64-bit)
- Operating System (e.g. Windows, macOS, Ubuntu): Windows
Activity
crisbeto commentedon Nov 25, 2026
It's a framework issue: angular/angular#70465