fix: prevent duplicate dependencies without using array.includes (#17503)

* fix: prevent duplicate dependencies without using array.includes

* changeset
pull/17508/head
Rich Harris 1 week ago committed by GitHub
parent d3776c1723
commit f679259232
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: faster deduplication of dependencies

@ -309,6 +309,20 @@ export function update_reaction(reaction) {
if (previous_reaction !== null && previous_reaction !== reaction) {
read_version++;
// update the `rv` of the previous reaction's deps — both existing and new —
// so that they are not added again
if (previous_reaction.deps !== null) {
for (let i = 0; i < previous_skipped_deps; i += 1) {
previous_reaction.deps[i].rv = read_version;
}
}
if (previous_deps !== null) {
for (const dep of previous_deps) {
dep.rv = read_version;
}
}
if (untracked_writes !== null) {
if (previous_untracked_writes === null) {
previous_untracked_writes = untracked_writes;
@ -526,7 +540,7 @@ export function get(signal) {
skipped_deps++;
} else if (new_deps === null) {
new_deps = [signal];
} else if (!new_deps.includes(signal)) {
} else {
new_deps.push(signal);
}
}

Loading…
Cancel
Save