Commit 7e73ebf
authored
fix(arrows): skip rendering empty label in SVG export (tldraw#8137)
Closes tldraw#7055. When exporting arrows without text labels via
`getSvgElement()`, the `<foreignObject>` element receives negative
width/height values (e.g. `-8.5`), causing browser console errors.
The root cause is in `ArrowShapeUtil.toSvg()`: it unconditionally
renders a `RichTextSVG` for the arrow label and applies
`.expandBy(-ARROW_LABEL_PADDING * scale)` to shrink the bounds by
padding. For empty labels, `getArrowLabelPosition()` returns a
zero-sized box, so subtracting `4.25 * 2 = 8.5` produces negative
dimensions.
The fix skips rendering `RichTextSVG` entirely when the label is empty,
matching the existing guard in the canvas rendering path.
### Change type
- [x] `bugfix`
### Test plan
1. Create an arrow with no text label
2. Export as SVG (File > Export as SVG)
3. Check the browser console — no more `<foreignObject> attribute width:
A negative value is not valid` errors
4. Create an arrow with a text label and export — label renders
correctly
### Release notes
- Fix arrow SVG export producing invalid negative `<foreignObject>`
dimensions when arrows have no text label
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk: a small conditional render change limited to SVG export
output, with no impact on arrow geometry or editing behavior beyond
avoiding invalid `<foreignObject>` dimensions.
>
> **Overview**
> Fixes arrow SVG export emitting invalid `<foreignObject>` sizes when
an arrow has no text label.
>
> `ArrowShapeUtil.toSvg()` now conditionally renders `RichTextSVG` only
when `richText` is non-empty, avoiding negative label bounds after
padding is applied.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
58fb598. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 11911bd commit 7e73ebf
1 file changed
Lines changed: 17 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
| 1083 | + | |
| 1084 | + | |
1083 | 1085 | | |
1084 | 1086 | | |
1085 | 1087 | | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
1099 | 1103 | | |
1100 | 1104 | | |
1101 | 1105 | | |
| |||
0 commit comments