File tree Expand file tree Collapse file tree
apps/sim/content/blog/agent-as-yjs-peer/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -322,6 +322,7 @@ export function AgentPeerDemo() {
322322
323323 let raf = 0
324324 let played = false
325+ let cancelled = false
325326
326327 const play = ( ) => {
327328 // Clear to empty only once on-screen, so the doc is never left blank if the observer never fires.
@@ -333,6 +334,7 @@ export function AgentPeerDemo() {
333334 let lastH = 0
334335 let lastA = 0
335336 const tick = ( now : number ) => {
337+ if ( cancelled ) return // cleanup ran (unmount / Strict Mode re-run); stop rescheduling
336338 const t = now - start
337339 if ( t >= RUN_MS ) {
338340 if ( lastH !== HUMAN_TOTAL ) setHumanN ( HUMAN_TOTAL )
@@ -367,6 +369,7 @@ export function AgentPeerDemo() {
367369 io . observe ( el )
368370
369371 return ( ) => {
372+ cancelled = true
370373 io . disconnect ( )
371374 if ( raf ) cancelAnimationFrame ( raf )
372375 }
You can’t perform that action at this time.
0 commit comments