mirror of https://github.com/sveltejs/svelte
fix: ensure if block is executed in correct order (#10053)
* fix: ensure if block is executed in correct order * alternative approach * improve algo * optimize * lintpull/10055/head
parent
98a72f5068
commit
1e33ed5bb9
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure if block is executed in correct order
|
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
const { item } = $props();
|
||||
</script>
|
||||
|
||||
<div>
|
||||
{#if item}
|
||||
{item.length}
|
||||
{/if}
|
||||
</div>
|
@ -0,0 +1,26 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target, component }) {
|
||||
const [b1, b2] = target.querySelectorAll('button');
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<div>5</div><div>5</div><div>3</div><button>set null</button><button>set object</button'
|
||||
);
|
||||
flushSync(() => {
|
||||
b2.click();
|
||||
});
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<div>5</div><div>5</div><div>3</div><button>set null</button><button>set object</button'
|
||||
);
|
||||
flushSync(() => {
|
||||
b1.click();
|
||||
});
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<div>5</div><div></div><div>3</div><button>set null</button><button>set object</button'
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
import Component from './Component.svelte';
|
||||
|
||||
let items = $state(['hello', 'world', 'bye']);
|
||||
</script>
|
||||
|
||||
{#each items as item}
|
||||
<Component {item} />
|
||||
{/each}
|
||||
|
||||
<button onclick={() => (items[1] = null)}> set null </button>
|
||||
<button onclick={() => (items[1] = 'hello')}> set object </button>
|
Loading…
Reference in new issue