Skip to content

Commit df54aa1

Browse files
committed
fix(blog): guard agent demo against missing/never-firing IntersectionObserver
1 parent 6e8f738 commit df54aa1

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

apps/sim/content/blog/agent-as-yjs-peer/components/agent-peer-demo.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,18 @@ export function AgentPeerDemo() {
316316
typeof window !== 'undefined' &&
317317
window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
318318
const el = cardRef.current
319-
if (reduce || !el) return
319+
// Reduced motion, no element, or an environment without IntersectionObserver (older browsers,
320+
// some test runners): leave the finished document in place as the fallback and never clear it.
321+
if (reduce || !el || typeof IntersectionObserver === 'undefined') return
320322

321323
let raf = 0
322324
let played = false
323-
// Hold at empty until the reader reaches it, so they watch it type rather than arriving to a
324-
// finished doc that quietly retypes.
325-
setHumanN(0)
326-
setAgentN(0)
327325

328326
const play = () => {
327+
// Clear to empty only now that the demo is actually on screen, so it's never left blank if the
328+
// observer never fires (the element never reaches the visibility threshold).
329+
setHumanN(0)
330+
setAgentN(0)
329331
const start = performance.now()
330332
// A character lands every ~30–60ms but frames fire every ~16ms, so most frames reveal nothing
331333
// new. Track the last emitted counts and only setState on an actual change, so React renders

0 commit comments

Comments
 (0)