svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
10.95k stars 1.07k forks source link

Moving a text with an inside title element fails #1304

Closed Shiuyin closed 10 months ago

Shiuyin commented 1 year ago

If you have a text element with a title element inside, moving that text element will fail with:

Uncaught TypeError: Cannot read properties of undefined (reading 'newLined') at Dom.<anonymous> (Text.js:56:22) at Text.each (Dom.js:84:13) at Text.rebuild (Text.js:50:12) at Text.attr (attr.js:79:12) at Text.ax (textable.js:68:15)

DOM: <text x="200" y="294">row10<title>row10</title></text>

Reason: .ax() is leading to a rebuild of the text element. Rebuilding the text element will also go through all children. When reaching the title child element, there is no this.dom.

Shiuyin commented 1 year ago

If your text elements are not multiline, you can use the following workaround:

textElement.rebuild(false)

This will prevent rebuilding (which seems to be only necessary for multiline support in text elements) and therefore prevent the NP.

Fuzzyma commented 10 months ago

I attempted to fix it here: https://github.com/svgdotjs/svg.js/commit/8fa0873a632f828ed1ad85aa30dee97bc585d32f

Please test and report back if it works for you. Sorry for the long wait!

Shiuyin commented 4 months ago

@Fuzzyma Thank you for your work. It works as intended now. When can we get a new build in order to profit from these fixes?

Fuzzyma commented 2 weeks ago

I am sorry, I somehow forgot to publish all the fixes I made. I just released it: https://github.com/svgdotjs/svg.js/releases/tag/3.2.1