mirror of https://github.com/sveltejs/svelte
feat: add `idPrefix` to `render` (#15428)
This ensures someone like Astro can render multiple islands and the unique ids produced in them are able to be deduplicated --------- Co-authored-by: Hugos68 <hugokorteapple@gmail.com> Co-authored-by: paoloricciuti <ricciutipaolo@gmail.com> Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/15431/head
parent
7ce2dfc622
commit
b82692af2f
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': minor
|
||||
---
|
||||
|
||||
feat: Add `idPrefix` option to `render`
|
@ -1,5 +1,6 @@
|
||||
import { PUBLIC_VERSION } from '../version.js';
|
||||
|
||||
if (typeof window !== 'undefined')
|
||||
// @ts-ignore
|
||||
(window.__svelte ||= { v: new Set() }).v.add(PUBLIC_VERSION);
|
||||
if (typeof window !== 'undefined') {
|
||||
// @ts-expect-error
|
||||
((window.__svelte ??= {}).v ??= new Set()).add(PUBLIC_VERSION);
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
let id = $props.id();
|
||||
</script>
|
||||
|
||||
<p>{id}</p>
|
@ -0,0 +1,60 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
id_prefix: 'myPrefix',
|
||||
test({ assert, target, variant }) {
|
||||
if (variant === 'dom') {
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle</button>
|
||||
<h1>c1</h1>
|
||||
<p>c2</p>
|
||||
<p>c3</p>
|
||||
<p>c4</p>
|
||||
`
|
||||
);
|
||||
} else {
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle</button>
|
||||
<h1>myPrefix-s1</h1>
|
||||
<p>myPrefix-s2</p>
|
||||
<p>myPrefix-s3</p>
|
||||
<p>myPrefix-s4</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
let button = target.querySelector('button');
|
||||
flushSync(() => button?.click());
|
||||
|
||||
if (variant === 'dom') {
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle</button>
|
||||
<h1>c1</h1>
|
||||
<p>c2</p>
|
||||
<p>c3</p>
|
||||
<p>c4</p>
|
||||
<p>c5</p>
|
||||
`
|
||||
);
|
||||
} else {
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle</button>
|
||||
<h1>myPrefix-s1</h1>
|
||||
<p>myPrefix-s2</p>
|
||||
<p>myPrefix-s3</p>
|
||||
<p>myPrefix-s4</p>
|
||||
<p>c1</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import Child from './Child.svelte';
|
||||
|
||||
let id = $props.id();
|
||||
|
||||
let show = $state(false);
|
||||
</script>
|
||||
|
||||
<button onclick={() => show = !show}>toggle</button>
|
||||
|
||||
<h1>{id}</h1>
|
||||
|
||||
<Child />
|
||||
<Child />
|
||||
<Child />
|
||||
|
||||
{#if show}
|
||||
<Child />
|
||||
{/if}
|
Loading…
Reference in new issue