fix: optimize `bind:group` (#12406)

pull/12419/head
Rich Harris 4 months ago committed by GitHub
parent bf0d1efb00
commit 36a6a6b789
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: optimize `bind:group`

@ -53,8 +53,11 @@ export function bind_value(input, get_value, update) {
}); });
} }
/** @type {Set<HTMLInputElement[]>} */
const pending = new Set();
/** /**
* @param {Array<HTMLInputElement>} inputs * @param {HTMLInputElement[]} inputs
* @param {null | [number]} group_index * @param {null | [number]} group_index
* @param {HTMLInputElement} input * @param {HTMLInputElement} input
* @param {() => unknown} get_value * @param {() => unknown} get_value
@ -127,10 +130,17 @@ export function bind_group(inputs, group_index, input, get_value, update) {
} }
}); });
if (!pending.has(binding_group)) {
pending.add(binding_group);
queue_micro_task(() => { queue_micro_task(() => {
// necessary to maintain binding group order in all insertion scenarios. TODO optimise // necessary to maintain binding group order in all insertion scenarios
binding_group.sort((a, b) => (a.compareDocumentPosition(b) === 4 ? -1 : 1)); binding_group.sort((a, b) => (a.compareDocumentPosition(b) === 4 ? -1 : 1));
pending.delete(binding_group);
});
}
queue_micro_task(() => {
if (hydration_mismatch) { if (hydration_mismatch) {
var value; var value;

Loading…
Cancel
Save