Skip to content

Commit d5f0b6c

Browse files
committed
fix
1 parent ab0b259 commit d5f0b6c

File tree

2 files changed

+15
-4
lines changed
  • packages/svelte/src/internal/client

2 files changed

+15
-4
lines changed

packages/svelte/src/internal/client/dom/elements/bindings/input.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,18 @@ export function bind_value(input, get, set = get) {
7676

7777
var value = get();
7878

79-
if (input === document.activeElement && batches.has(/** @type {Batch} */ (previous_batch))) {
79+
if (input === document.activeElement) {
80+
// we need both, because in non-async mode, render effects run before previous_batch is set
81+
var batch = /** @type {Batch} */ (previous_batch ?? current_batch);
82+
8083
// Never rewrite the contents of a focused input. We can get here if, for example,
8184
// an update is deferred because of async work depending on the input:
8285
//
8386
// <input bind:value={query}>
8487
// <p>{await find(query)}</p>
85-
return;
88+
if (batches.has(batch)) {
89+
return;
90+
}
8691
}
8792

8893
if (is_numberlike_input(input) && value === to_number(input.value)) {

packages/svelte/src/internal/client/reactivity/batch.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ const batches = new Set();
3838
/** @type {Batch | null} */
3939
export let current_batch = null;
4040

41-
/** @type {Batch | null} */
42-
export let previous_batch = current_batch;
41+
/**
42+
* This is needed to avoid overwriting inputs in non-async mode
43+
* TODO 6.0 remove this, as non-async mode will go away
44+
* @type {Batch | null}
45+
*/
46+
export let previous_batch = null;
4347

4448
/**
4549
* When time travelling, we re-evaluate deriveds based on the temporary
@@ -175,6 +179,8 @@ export class Batch {
175179
process(root_effects) {
176180
queued_root_effects = [];
177181

182+
previous_batch = null;
183+
178184
/** @type {Map<Source, { v: unknown, wv: number }> | null} */
179185
var current_values = null;
180186

0 commit comments

Comments
 (0)