Skip to content

Conversation

@jleen
Copy link

@jleen jleen commented Mar 8, 2025

snabbdom-jsx wasn’t correctly handling svg tags inside of svg tags. considerSVG was double-converting them, leading to an invalid DOM. Similarly, foreignObject inside of svg was getting converted incorrectly. This patch adds unit tests for both of these cases, and adds a check in considerSVG to avoid incorrect conversion.

expect(
<svg id="foo" className="wrapper" viewBox="25 25 50 50">
<circle id="baz" className="circle" cx="50" cy="50" r="20" />
<svg id="bar" className="inner" viewBox="1 2 3 4">
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first case that’s fixed by my PR: an svg within an svg. Formerly, the inner svg was having its attributes erased due to double conversion.

Copy link
Author

@jleen jleen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your useful library. This little change fixes a couple of bugs that I encountered.

<circle id="ding" className="ball" cx="40" cy="50" r="60" />
</svg>
<foreignObject id="xyzzy" className="abc">
<a href="quux"/>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the second case that I’m fixing: an HTML tag within a foreign object was also having its props erased.

return data;
};

const tagFromSel = (sel: String | undefined): String | undefined => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this utility method so that considerSVG can easily determine what its child tags are. I couldn’t think of a simpler way to do this, but I’m open to suggestions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant