Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

DebugElement.classes does not work for SVG elements in Ivy #34868

Closed
euangoddard opened this issue Jan 20, 2020 · 2 comments
Closed

DebugElement.classes does not work for SVG elements in Ivy #34868

euangoddard opened this issue Jan 20, 2020 · 2 comments
Assignees
Labels
area: core Issues related to the framework runtime regression Indicates than the issue relates to something that worked in a previous version state: has PR
Milestone

Comments

@euangoddard
Copy link

euangoddard commented Jan 20, 2020

馃悶 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

Yes. Angular 8.x and before

Description

In unit tests when inspecting the classes property of a DebugElement which wraps an SVGElement, the error:

TypeError: element.className.split is not a function

is thrown.

I can reproduce this error in the web browser by selecting an arbitrary SVG element (e.g. document.querySelector('svg') and accessing svgElement.classList.split(' '); on this element.

The affected line of code is:

const classNames = element.className.split(' ');
and this only happens with SVG elements

馃敩 Minimal Reproduction

I can't get this to work in StackBlitz - it looks like Ivy isn't enabled there for some reason. I have made this repo with instructions in the README: https://github.com/euangoddard/svg-debug-element

馃敟 Exception or Error


core.js:6406 ERROR TypeError: element.className.split is not a function
    at DebugElement__POST_R3__.get classes [as classes] (core.js:44232)
    at AppComponent.showClasses (app.component.ts:47)
    at AppComponent_Template_button_click_10_listener (app.component.ts:24)
    at executeListenerWithErrorHandling (core.js:24408)
    at wrapListenerIn_markDirtyAndPreventDefault (core.js:24450)
    at HTMLButtonElement. (platform-browser.js:928)
    at ZoneDelegate.invokeTask (zone-evergreen.js:400)
    at Object.onInvokeTask (core.js:41740)
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Zone.runTask (zone-evergreen.js:168)

馃實 Your Environment

Angular Version:


Angular CLI: 9.0.0-rc.9
Node: 12.14.1
OS: darwin x64

Angular: 9.0.0-rc.9
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.9
@angular-devkit/build-angular     0.900.0-rc.9
@angular-devkit/build-optimizer   0.900.0-rc.9
@angular-devkit/build-webpack     0.900.0-rc.9
@angular-devkit/core              9.0.0-rc.9
@angular-devkit/schematics        9.0.0-rc.9
@ngtools/webpack                  9.0.0-rc.9
@schematics/angular               9.0.0-rc.9
@schematics/update                0.900.0-rc.9
rxjs                              6.5.4
typescript                        3.6.4
webpack                           4.41.2
@euangoddard
Copy link
Author

Looking at the documentation here, it would appear that svgElement.className returns SVGAnimatedString and not DOMString as htmlElement.className returns. I'm happy to make a PR for this, but am unsure of the best way to cater for this (e.g. using an instanceof check and reading the baseVal in the case of SVGAnimatedString

@crisbeto crisbeto self-assigned this Jan 20, 2020
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 20, 2020
Fixes Ivy throwing an error when trying to access the `DebugNode.classes` of an SVG element. The problem is that the `className` of an SVG element is an `SVGAnimatedString`, rather than a plain string.

Fixes angular#34868.
@crisbeto crisbeto added area: core Issues related to the framework runtime comp: ivy state: has PR labels Jan 20, 2020
@ngbot ngbot bot modified the milestone: needsTriage Jan 20, 2020
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 20, 2020
Fixes Ivy throwing an error when trying to access the `DebugNode.classes` of an SVG element. The problem is that the `className` of an SVG element is an `SVGAnimatedString`, rather than a plain string.

Fixes angular#34868.
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 20, 2020
Fixes Ivy throwing an error when trying to access the `DebugNode.classes` of an SVG element. The problem is that the `className` of an SVG element is an `SVGAnimatedString`, rather than a plain string.

Fixes angular#34868.
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 20, 2020
Fixes Ivy throwing an error when trying to access the `DebugNode.classes` of an SVG element. The problem is that the `className` of an SVG element is an `SVGAnimatedString`, rather than a plain string.

Fixes angular#34868.
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 20, 2020
Fixes Ivy throwing an error when trying to access the `DebugNode.classes` of an SVG element. The problem is that the `className` of an SVG element is an `SVGAnimatedString`, rather than a plain string.

Fixes angular#34868.
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 20, 2020
Fixes Ivy throwing an error when trying to access the `DebugNode.classes` of an SVG element. The problem is that the `className` of an SVG element is an `SVGAnimatedString`, rather than a plain string.

Fixes angular#34868.
AndrewKushnir pushed a commit that referenced this issue Jan 22, 2020
Fixes Ivy throwing an error when trying to access the `DebugNode.classes` of an SVG element. The problem is that the `className` of an SVG element is an `SVGAnimatedString`, rather than a plain string.

Fixes #34868.

PR Close #34872
@kara kara added regression Indicates than the issue relates to something that worked in a previous version and removed severity5: ivy-compat labels Feb 11, 2020
sonukapoor pushed a commit to sonukapoor/angular that referenced this issue Feb 13, 2020
Fixes Ivy throwing an error when trying to access the `DebugNode.classes` of an SVG element. The problem is that the `className` of an SVG element is an `SVGAnimatedString`, rather than a plain string.

Fixes angular#34868.

PR Close angular#34872
@angular-automatic-lock-bot
Copy link

This issue 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 Mar 13, 2020
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 regression Indicates than the issue relates to something that worked in a previous version state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants