mirror of https://github.com/sveltejs/svelte
fix: always reconnect deriveds in get, when appropriate (#17451)
* failing test * fix: always reconnect deriveds in get, when appropriate * shuffle code around a bit * note to selfpull/17410/head
parent
2c23390286
commit
ae224bea49
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: always reconnect deriveds in get, when appropriate
|
||||
@ -0,0 +1,24 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [fork] = target.querySelectorAll('button');
|
||||
|
||||
fork.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, '<button>fork</button><button>false</button>');
|
||||
|
||||
const [, toggle] = target.querySelectorAll('button');
|
||||
|
||||
toggle.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, '<button>fork</button><button>true</button>');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,26 @@
|
||||
<script>
|
||||
import { fork } from 'svelte';
|
||||
|
||||
let condition = $state(false);
|
||||
let checked = $state(false);
|
||||
|
||||
const d = $derived({ checked });
|
||||
</script>
|
||||
|
||||
<button onclick={() => {
|
||||
fork(() => {
|
||||
condition = true;
|
||||
}).commit();
|
||||
}}>fork</button>
|
||||
|
||||
{#if condition}
|
||||
<!-- in dev, snippet arguments are read eagerly, outside a tracking context -->
|
||||
<!-- this test checks that doing so doesn't prevent the derived from connecting -->
|
||||
{#snippet foo({ checked })}
|
||||
{checked}
|
||||
{/snippet}
|
||||
|
||||
<button onclick={() => (checked = !checked)}>
|
||||
{@render foo(d)}
|
||||
</button>
|
||||
{/if}
|
||||
Loading…
Reference in new issue