Skip to content

Commit 1f3fcb9

Browse files
committed
fix(landing): reset demo step index when the preview auto-cycle restarts
- reactive isDesktop can re-run the demo effect on a 1024px resize; reset demoIndexRef to 0 so applyDemoStep(step 0) and scheduleNextStep read the same step, instead of replaying from a stale index and skipping beats - clarify why the chat reveal's previous-value ref is safe here (timer-driven, no concurrent-interruption boundary)
1 parent 13162f3 commit 1f3fcb9

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

apps/sim/app/(landing)/components/landing-preview/components/landing-preview-chat/landing-preview-chat.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ export function LandingPreviewChat({ chat, chatName, animationKey }: LandingPrev
4545
const [phase, setPhase] = useState<RevealPhase>('hidden')
4646
const revealRef = useRef<{ key: number; chat: PreviewChat | null }>({ key: animationKey, chat })
4747

48-
// Restart the reveal synchronously when the timeline (or staged chat) changes,
49-
// so the pane never flashes the previous step's reply before the effect reruns.
48+
// Restart the reveal synchronously when the timeline (or staged chat) changes, so
49+
// the pane never flashes the previous step's reply before the effect reruns. The
50+
// previous key/chat are tracked in a ref: these updates come from the parent's
51+
// timer-driven state (never a transition/Suspense boundary), so the render can't be
52+
// discarded between the ref write and commit - keeping the ref safe here.
5053
if (revealRef.current.key !== animationKey || revealRef.current.chat !== chat) {
5154
revealRef.current = { key: animationKey, chat }
5255
setPhase('hidden')

apps/sim/app/(landing)/components/landing-preview/landing-preview.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ export function LandingPreview({
183183
// the auto-demo on the cycle still being active - a resize after the visitor
184184
// has interacted must not restart the sequence from the first step.
185185
if (!isDesktop || !autoplay || !autoCycleActiveRef.current) return
186+
// Reset the step index so the restart shows step 0 AND `scheduleNextStep` reads
187+
// step 0's delay - otherwise a resize would replay from a stale index and skip beats.
188+
demoIndexRef.current = 0
186189
applyDemoStep(DESKTOP_STEPS[0])
187190
scheduleNextStep()
188191
return clearDemoTimer

0 commit comments

Comments
 (0)