[BUG] SVG Element is not a real SVGElement
Question
Behavior I use an external Javascript code that replaces some SVG elements dynamically based on their attributes. The Javascript code first checks for the type of the element to validate, that it is an SVGElement like this:
document.querySelector('#someId') instanceof SVGElement
The code returns True in Firefox but False in Safari and Chrome although I can verify in the Chrome Properties tab, that it is indeed of type SVGElement.
How I create the SVG Element I tried different things but ended up using a Plugin.
component.js
domc.addType('myType', {
isComponent: function(el) {
if(el.tagName == 'svg' && el.classList && el.classList.contains('someClass'))
return {type: 'myType'};
},
extend: 'svg',
model: {
defaults: {
type: 'svg',
tagName: 'svg',
name: 'SomeName',
traits: [...],
attributes: {
class:'someClass',
...
},
script: function () {
console.log(document.querySelector('.someClass'));
console.log(document.querySelector('.someClass') instanceof SVGElement)
...
},
}
}
});
blocks.js
bm.add('myBlock', {
label: 'someLabel',
category: 'someCategory',
name: 'blockName',
content: '<svg class="someClass"\
...\
</svg>'
});
Additional Information According to this: https://stackoverflow.com/questions/24174975/document-createelementsvg-instanceof-svgelement-is-false SVG elements are special, but from what I can see in src/dom_components/view/ComponentSvgView.js I assume, that they are created correctly.
Of course there is nothing wrong with the generated HTML-Code when using it, as browsers will then use the correct SVG - it is just not showing up when editing in GrapesJS.
Answers (1)
The code returns True in Firefox but False in Safari and Chrome although I can verify in the Chrome Properties tab, that it is indeed of type SVGElement.
Weird, seems like a Chromium issue...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3397
BUG: sorter direction incorrect with web component slot
Version:0.16.45 Are you able to reproduce the bug from the demo?[x] Yes[ ] No What is the expected behavior? Given a parent web component i...
Issue #826
[Bug] Element auto generated id not added back after custom id is used and then cleared
Hi, I think there is a bug related to the generation of element id attributes. When modifying element's style the value of the element's id...
Issue #3396
BUG: flex-direction: column & float: left make sorter direction incorrect
Version:0.16.45 Are you able to reproduce the bug from the demo?[x] Yes[ ] No What is the expected behavior? Given a parent element with di...
Issue #4854
BUG: export 'default' not found in 'backbone' (module has no exports)
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Firefox 109 Reproducible demo link none De...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.