mirror of https://github.com/sveltejs/svelte
fix: move ownership validation into async component body (#16449)
* fix: move ownership validation into async component body * add test --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/16445/head
parent
63cbe2108a
commit
ad0b58ee96
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: move ownership validation into async component body
|
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
let { object } = $props();
|
||||||
|
|
||||||
|
await 1;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => object.count++}>clicks: {object.count}</button>
|
@ -0,0 +1,22 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target, warnings }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const [button] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
button.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>clicks: 1</button>');
|
||||||
|
assert.deepEqual(warnings, [
|
||||||
|
'Mutating unbound props (`object`, at Child.svelte:7:23) is strongly discouraged. Consider using `bind:object={...}` in main.svelte (or using a callback) instead'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
|
let object = $state({ count: 0 });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
<Child {object} />
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>loading...</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
Loading…
Reference in new issue