Skip to content

bug(MatPaginator ): Component created via ViewContainerRef inside an @if block that follows an <svg> gets the SVG namespace (MatPaginator "Last page" tooltip is invisible) #34185

Done

Description

@jakubkirylo

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:

  1. The compiler emits ɵɵnamespaceSVG() / ɵɵnamespaceHTML() only before element start instructions (namespace phase of the template pipeline). Container instructions such as ɵɵconditionalCreate do not get a namespace instruction before them.
  2. ɵɵelementEnd() does not reset the current namespace. After <button><svg>…</svg></button>, currentNamespace is still svg.
  3. 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 @if is created by createTNode with namespace: getNamespace(), so it stores svg, a leftover value that does not describe any real element.
  4. The "Last page" button itself is created correctly as HTML, because every embedded view starts with a clean currentNamespace.
  5. MatTooltip creates TooltipComponent through the button's ViewContainerRef. R3ViewContainerRef._getHostElementNamespace() takes the namespace of the host TNode's parent. For the root element of an embedded view, that parent is the @if container TNode (_hostLView[T_HOST]), so it returns svg.
  6. createHostElement() then calls renderer.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's namespace. The existing foreignObject check 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:

  1. 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

  1. added
    needs triage
    on Nov 25, 2026
  2. crisbeto commented on Nov 25, 2026

    @crisbeto
    Member

    It's a framework issue: angular/angular#70465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: material/paginatorneeds triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions