Skip to content

Commit 4d3b294

Browse files
fix(core): prevent duplicate setInterval in dispatchEvent (#683)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 56c34dd commit 4d3b294

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stackflow/core": patch
3+
---
4+
5+
fix(core): prevent duplicate setInterval in dispatchEvent

core/src/makeCoreStore.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export function makeCoreStore(options: MakeCoreStoreOptions): CoreStore {
8484
value: aggregate(events.value, new Date().getTime()),
8585
};
8686

87+
let currentInterval: ReturnType<typeof setInterval> | null = null;
88+
8789
const actions: StackflowActions = {
8890
getStack() {
8991
return stack.value;
@@ -98,6 +100,10 @@ export function makeCoreStore(options: MakeCoreStoreOptions): CoreStore {
98100
events.value.push(newEvent);
99101
setStackValue(nextStackValue);
100102

103+
if (currentInterval !== null) {
104+
clearInterval(currentInterval);
105+
}
106+
101107
const interval = setInterval(() => {
102108
const nextStackValue = aggregate(events.value, new Date().getTime());
103109

@@ -107,8 +113,12 @@ export function makeCoreStore(options: MakeCoreStoreOptions): CoreStore {
107113

108114
if (nextStackValue.globalTransitionState === "idle") {
109115
clearInterval(interval);
116+
if (currentInterval === interval) {
117+
currentInterval = null;
118+
}
110119
}
111120
}, INTERVAL_MS);
121+
currentInterval = interval;
112122
},
113123
push: () => {},
114124
replace: () => {},

0 commit comments

Comments
 (0)