Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-clocks-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: improve consistency issues around binding invalidation
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,20 @@ export function pre_effect(init) {
);
}

/**
* @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}
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/internal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
user_effect,
render_effect,
pre_effect,
invalidate_effect,
flushSync,
bubble_event,
safe_equal,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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');
}
});
Original file line number Diff line number Diff line change
@@ -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>