mirror of https://github.com/sveltejs/svelte
fix: create `<svelte:element>` instances with the correct namespace (#10006)
Infer namespace from parents where possible, and do a runtime-best-effort where it's not statically known fixes #9645 --------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/10333/head
parent
5ebd9e0b45
commit
77b4c4be6c
@ -0,0 +1,16 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
// This is skipped for now, because it's not clear how to make this work on client-side initial run:
|
||||||
|
// The anchor isn't connected to its parent at the time we can do a runtime check for the namespace, and we
|
||||||
|
// need the parent for this check. (this didn't work in Svelte 4 either)
|
||||||
|
skip: true,
|
||||||
|
html: '<svg><path></path></svg>',
|
||||||
|
|
||||||
|
test({ assert, target }) {
|
||||||
|
const svg = target.querySelector('svg');
|
||||||
|
const rect = target.querySelector('path');
|
||||||
|
assert.equal(svg?.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||||
|
assert.equal(rect?.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
// ensure these are treated as dynamic, despite whatever
|
||||||
|
// optimisations we might apply
|
||||||
|
export let svg = 'svg';
|
||||||
|
export let path = 'path';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:element this={svg}>
|
||||||
|
<svelte:element this={path}></svelte:element>
|
||||||
|
</svelte:element>
|
@ -0,0 +1,20 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
test({ assert, target }) {
|
||||||
|
const [svg1, svg2] = target.querySelectorAll('svg');
|
||||||
|
const [path1, path2] = target.querySelectorAll('path');
|
||||||
|
const [fO1, fO2] = target.querySelectorAll('foreignObject');
|
||||||
|
const [span1, span2] = target.querySelectorAll('span');
|
||||||
|
|
||||||
|
assert.equal(svg1.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||||
|
assert.equal(path1.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||||
|
|
||||||
|
assert.equal(svg2.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||||
|
assert.equal(path2.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||||
|
assert.equal(fO1.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||||
|
assert.equal(span1.namespaceURI, 'http://www.w3.org/1999/xhtml');
|
||||||
|
assert.equal(fO2.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||||
|
assert.equal(span2.namespaceURI, 'http://www.w3.org/1999/xhtml');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,22 @@
|
|||||||
|
<script>
|
||||||
|
const iconNode = [["path", { "d": "M21 12a9 9 0 1 1-6.219-8.56" }]];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svg>
|
||||||
|
{#each iconNode as [tag, attrs]}
|
||||||
|
<svelte:element this={tag} {...attrs}/>
|
||||||
|
{/each}
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<svg>
|
||||||
|
<svelte:element this="path">
|
||||||
|
<foreignObject>
|
||||||
|
<svelte:element this="span">ok</svelte:element>
|
||||||
|
</foreignObject>
|
||||||
|
<foreignObject>
|
||||||
|
{#if true}
|
||||||
|
<svelte:element this="span">ok</svelte:element>
|
||||||
|
{/if}
|
||||||
|
</foreignObject>
|
||||||
|
</svelte:element>
|
||||||
|
</svg>
|
Loading…
Reference in new issue