fix: improve consistency issues around binding invalidation ()

* co

* Add comment
pull/9811/head
Dominic Gannaway 1 year ago committed by GitHub
parent 01a2117330
commit d793d570e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: improve consistency issues around binding invalidation

@ -245,7 +245,7 @@ function setup_select_synchronization(value_binding, context) {
context.state.init.push(
b.stmt(
b.call(
'$.pre_effect',
'$.invalidate_effect',
b.thunk(
b.block([
b.stmt(

@ -1273,6 +1273,17 @@ export function pre_effect(init) {
);
}
/**
* This effect is used to ensure binding are kept in sync. We use a pre effect to ensure we run before the
* bindings which are in later effects. However, we don't use a pre_effect directly as we don't want to flush anything.
*
* @param {() => void | (() => void)} init
* @returns {import('./types.js').EffectSignal}
*/
export function invalidate_effect(init) {
return internal_create_effect(PRE_EFFECT, init, true, current_block, true);
}
/**
* @param {() => void | (() => void)} init
* @returns {import('./types.js').EffectSignal}

@ -12,6 +12,7 @@ export {
user_effect,
render_effect,
pre_effect,
invalidate_effect,
flushSync,
bubble_event,
safe_equal,

@ -0,0 +1,16 @@
import { test } from '../../test';
export default test({
async test({ assert, target }) {
assert.htmlEqual(target.innerHTML, 'a\n<select></select><button>change</button');
const [b1] = target.querySelectorAll('button');
b1.click();
await Promise.resolve();
assert.htmlEqual(
target.innerHTML,
'a\n<select></select>b\n<select></select><button>change</button'
);
}
});

@ -0,0 +1,13 @@
<script>
let entries = $state([{selected: 'a'}])
</script>
{#each entries as entry}
{entry.selected} <select bind:value={entry.selected}></select>
{/each}
<button
on:click={
() => entries = [{selected: 'a'}, {selected: 'b'}]
}
>change</button>
Loading…
Cancel
Save