File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @stackflow/core " : patch
3+ ---
4+
5+ fix(core): prevent duplicate setInterval in dispatchEvent
Original file line number Diff line number Diff 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 : ( ) => { } ,
You can’t perform that action at this time.
0 commit comments