From 7e762cf481b06a8eeddcf6f1cea11d741c01a2dc Mon Sep 17 00:00:00 2001 From: Paolo Ricciuti Date: Fri, 31 May 2024 10:56:38 +0200 Subject: [PATCH] fix: reevaluate namespace in slots (#11849) Closes #11847 --- .changeset/shiny-months-tease.md | 5 +++++ packages/svelte/src/compiler/phases/3-transform/utils.js | 3 ++- .../tests/runtime-legacy/samples/slot-svg/_config.js | 9 +++++++++ .../tests/runtime-legacy/samples/slot-svg/main.svelte | 7 +++++++ .../tests/runtime-legacy/samples/slot-svg/points.svelte | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .changeset/shiny-months-tease.md create mode 100644 packages/svelte/tests/runtime-legacy/samples/slot-svg/_config.js create mode 100644 packages/svelte/tests/runtime-legacy/samples/slot-svg/main.svelte create mode 100644 packages/svelte/tests/runtime-legacy/samples/slot-svg/points.svelte diff --git a/.changeset/shiny-months-tease.md b/.changeset/shiny-months-tease.md new file mode 100644 index 0000000000..a4f3413cd4 --- /dev/null +++ b/.changeset/shiny-months-tease.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: reevaluate namespace in slots diff --git a/packages/svelte/src/compiler/phases/3-transform/utils.js b/packages/svelte/src/compiler/phases/3-transform/utils.js index 54ce062ad0..1e5ef8dce1 100644 --- a/packages/svelte/src/compiler/phases/3-transform/utils.js +++ b/packages/svelte/src/compiler/phases/3-transform/utils.js @@ -176,7 +176,8 @@ export function infer_namespace(namespace, parent, nodes) { parent.type === 'Component' || parent.type === 'SvelteComponent' || parent.type === 'SvelteFragment' || - parent.type === 'SnippetBlock' + parent.type === 'SnippetBlock' || + parent.type === 'SlotElement' ) { const new_namespace = check_nodes_for_namespace(nodes, 'keep'); if (new_namespace !== 'keep' && new_namespace !== 'maybe_html') { diff --git a/packages/svelte/tests/runtime-legacy/samples/slot-svg/_config.js b/packages/svelte/tests/runtime-legacy/samples/slot-svg/_config.js new file mode 100644 index 0000000000..de80ebe351 --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/slot-svg/_config.js @@ -0,0 +1,9 @@ +import { ok, test } from '../../test'; + +export default test({ + async test({ assert, target }) { + const circle = target.querySelector('circle'); + ok(circle); + assert.equal(circle.namespaceURI, 'http://www.w3.org/2000/svg'); + } +}); diff --git a/packages/svelte/tests/runtime-legacy/samples/slot-svg/main.svelte b/packages/svelte/tests/runtime-legacy/samples/slot-svg/main.svelte new file mode 100644 index 0000000000..faf271a00f --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/slot-svg/main.svelte @@ -0,0 +1,7 @@ + + + + + diff --git a/packages/svelte/tests/runtime-legacy/samples/slot-svg/points.svelte b/packages/svelte/tests/runtime-legacy/samples/slot-svg/points.svelte new file mode 100644 index 0000000000..eb580cf793 --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/slot-svg/points.svelte @@ -0,0 +1,3 @@ + + +