diff --git a/src/compiler/compile/render_dom/wrappers/Text.ts b/src/compiler/compile/render_dom/wrappers/Text.ts index 5247eacdb698..1978cba0d7d0 100644 --- a/src/compiler/compile/render_dom/wrappers/Text.ts +++ b/src/compiler/compile/render_dom/wrappers/Text.ts @@ -27,6 +27,11 @@ function should_skip(node: Text) { if (parent_element.type === 'Head') return true; if (parent_element.type === 'InlineComponent') return parent_element.children.length === 1 && node === parent_element.children[0]; + // svg namespace exclusions + if (/svg$/.test(parent_element.namespace)) { + if (node.prev && node.prev.type === "Element" && node.prev.name === "tspan") return false; + } + return parent_element.namespace || elements_without_text.has(parent_element.name); } diff --git a/test/runtime/samples/svg-tspan-preserve-space/_config.js b/test/runtime/samples/svg-tspan-preserve-space/_config.js new file mode 100644 index 000000000000..283af0a2b0c2 --- /dev/null +++ b/test/runtime/samples/svg-tspan-preserve-space/_config.js @@ -0,0 +1,3 @@ +export default { + html: `foo barfoo bar`, +}; diff --git a/test/runtime/samples/svg-tspan-preserve-space/main.svelte b/test/runtime/samples/svg-tspan-preserve-space/main.svelte new file mode 100644 index 000000000000..df43d575a906 --- /dev/null +++ b/test/runtime/samples/svg-tspan-preserve-space/main.svelte @@ -0,0 +1 @@ +foo {"bar"}foo bar \ No newline at end of file