Skip to content

Routed component host created in SVG namespace after an <svg> sibling (22.1.4) #70465

Description

@hypnotoad08

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

When a <router-outlet> sits inside an @if block and any <svg> appears
earlier in the same template
, the routed component's host element is created in
the SVG namespace. The <svg> is closed and is only a preceding sibling — the
outlet is not nested inside it.

An SVG-namespaced element gets no CSS box in HTML layout, so the routed view
computes to 0x0. The markup is fully present and correct in the DOM, every
computed style looks right, and no error or warning is logged — the page is
simply blank.

The @if is required. Without it the same <svg> causes no problem:

<svg> earlier in template outlet inside @if host namespace result
yes no HTML renders
yes yes SVG 0x0, blank

Nesting the <svg> inside another element (e.g. a <button>) makes no
difference; the @if is the deciding factor. Wrapping the outlet in any HTML
element inside the @if restores the HTML namespace and works around it.

Bisected to 2ab5ff5 ("fix(core): preserve namespace for dynamic component
hosts"), which changed createHostElement():

// 22.1.3
const namespace = tagName === 'svg' ? SVG_NAMESPACE : tagName === 'math' ? MATH_ML_NAMESPACE : null;
// 22.1.4
const namespace = tagName === 'svg' ? SVG_NAMESPACE : tagName === 'math' ? MATH_ML_NAMESPACE : hostElementNamespace;

Is this the intended consequence of that change? The outlet is not nested inside
the <svg> — the element is closed before the @if block begins — so it is not
obvious that the SVG namespace should reach the routed host here.

Please provide a link to a minimal reproduction of the bug

https://github.com/hypnotoad08/angular-svg-namespace-repro

Please provide the exception or error you saw

None. There is no exception and no console warning.

Please provide the environment you discovered this bug in (run ng version)

Angular CLI       : 22.1.6
Angular           : 22.1.4
Node.js           : 24.20.0
Package Manager   : npm 11.19.0
Operating System  : win32 x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 22.1.6            │ ^22.1.5           │
│ @angular/cli              │ 22.1.6            │ ^22.1.5           │
│ @angular/common           │ 22.1.4            │ ^22.1.3           │
│ @angular/compiler         │ 22.1.4            │ ^22.1.3           │
│ @angular/compiler-cli     │ 22.1.4            │ ^22.1.3           │
│ @angular/core             │ 22.1.4            │ ^22.1.3           │
│ @angular/forms            │ 22.1.4            │ ^22.1.3           │
│ @angular/platform-browser │ 22.1.4            │ ^22.1.3           │
│ @angular/router           │ 22.1.4            │ ^22.1.3           │
│ rxjs                      │ 7.8.2             │ ^7.8.2            │
│ typescript                │ 6.0.3             │ ~6.0.3            │
│ vitest                    │ 4.1.11            │ ^4.1.10           │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimegemini-triagedLabel noting that an issue has been triaged by gemini

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions