Skip to content

Commit 85ebf42

Browse files
committed
Avoid infinite loop by tracking previous head
Prevent infinite reactivity loops by storing the previous head value and only invalidating stacks and details when the head actually changes. The change introduces a previousHead state variable and uses untrack to update it and call stackService.invalidateStacksAndDetails() only when head differs from previousHead.
1 parent f3381ef commit 85ebf42

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

apps/desktop/src/routes/[projectId]/+layout.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,14 @@
206206
const head = $derived(headResponse.response);
207207
208208
// If the head changes, invalidate stacks and details
209+
// We need to track the previous head value to avoid infinite loops
210+
let previousHead = $state<string | undefined>(undefined);
209211
$effect(() => {
210-
if (head) {
211-
stackService.invalidateStacksAndDetails();
212+
if (head && head !== previousHead) {
213+
untrack(() => {
214+
previousHead = head;
215+
stackService.invalidateStacksAndDetails();
216+
});
212217
}
213218
});
214219

0 commit comments

Comments
 (0)