Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle duplicate signal dependencies gracefully #12261

Merged
merged 4 commits into from
Jul 2, 2024
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/witty-phones-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: handle duplicate signal dependencies gracefully
12 changes: 7 additions & 5 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,15 @@ function remove_reaction(signal, dependency) {
export function remove_reactions(signal, start_index) {
const dependencies = signal.deps;
if (dependencies !== null) {
const active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index);
var active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index);
var visited = new Set();
let i;
for (i = start_index; i < dependencies.length; i++) {
const dependency = dependencies[i];
if (visited.has(dependency)) {
continue;
}
visited.add(dependency);
// Avoid removing a reaction if we know that it is active (start_index will not be 0)
if (active_dependencies === null || !active_dependencies.includes(dependency)) {
remove_reaction(signal, dependency);
Expand Down Expand Up @@ -774,10 +779,7 @@ export function get(signal) {
) {
if (current_dependencies === null) {
current_dependencies = [signal];
} else if (
current_dependencies[current_dependencies.length - 1] !== signal &&
!current_dependencies.includes(signal)
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved
) {
} else if (current_dependencies[current_dependencies.length - 1] !== signal) {
current_dependencies.push(signal);
}
}
Expand Down
Loading