pull/16491/head
Rich Harris 2 months ago
parent ab0b259161
commit d5f0b6cf22

@ -76,13 +76,18 @@ export function bind_value(input, get, set = get) {
var value = get(); var value = get();
if (input === document.activeElement && batches.has(/** @type {Batch} */ (previous_batch))) { if (input === document.activeElement) {
// we need both, because in non-async mode, render effects run before previous_batch is set
var batch = /** @type {Batch} */ (previous_batch ?? current_batch);
// Never rewrite the contents of a focused input. We can get here if, for example, // Never rewrite the contents of a focused input. We can get here if, for example,
// an update is deferred because of async work depending on the input: // an update is deferred because of async work depending on the input:
// //
// <input bind:value={query}> // <input bind:value={query}>
// <p>{await find(query)}</p> // <p>{await find(query)}</p>
return; if (batches.has(batch)) {
return;
}
} }
if (is_numberlike_input(input) && value === to_number(input.value)) { if (is_numberlike_input(input) && value === to_number(input.value)) {

@ -38,8 +38,12 @@ const batches = new Set();
/** @type {Batch | null} */ /** @type {Batch | null} */
export let current_batch = null; export let current_batch = null;
/** @type {Batch | null} */ /**
export let previous_batch = current_batch; * This is needed to avoid overwriting inputs in non-async mode
* TODO 6.0 remove this, as non-async mode will go away
* @type {Batch | null}
*/
export let previous_batch = null;
/** /**
* When time travelling, we re-evaluate deriveds based on the temporary * When time travelling, we re-evaluate deriveds based on the temporary
@ -175,6 +179,8 @@ export class Batch {
process(root_effects) { process(root_effects) {
queued_root_effects = []; queued_root_effects = [];
previous_batch = null;
/** @type {Map<Source, { v: unknown, wv: number }> | null} */ /** @type {Map<Source, { v: unknown, wv: number }> | null} */
var current_values = null; var current_values = null;

Loading…
Cancel
Save