Skip to content

Commit 8e4931b

Browse files
committed
Fix a layout change flicker
1 parent e3a4500 commit 8e4931b

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/components/tutorial/TutorialWindow.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { Tabs, TabsContent } from "@radix-ui/react-tabs";
22
import { useNavigate, useRouter, useSearch } from "@tanstack/react-router";
33
import { DatabaseZapIcon, XIcon } from "lucide-react";
44
import { AnimatePresence, motion } from "motion/react";
5-
import { useCallback, useEffect, useRef, useState } from "react";
5+
import {
6+
useCallback,
7+
useEffect,
8+
useLayoutEffect,
9+
useRef,
10+
useState,
11+
} from "react";
612
import { steps } from "@/data/tutorial";
713
import { useScrollShadow } from "@/hooks/use-scroll-shadow";
814
import { cn } from "@/lib/utils";
@@ -188,15 +194,15 @@ function FloatingWindow({
188194
],
189195
);
190196

191-
// Restore scroll position on mount
192-
useEffect(() => {
193-
if (tutorialData.tutorialStep) {
194-
const saved = tutorialData.scrollPositions[tutorialData.tutorialStep];
197+
// Restore scroll position on step change (useLayoutEffect to avoid flicker)
198+
useLayoutEffect(() => {
199+
if (activeStep) {
200+
const saved = tutorialData.scrollPositions[activeStep];
195201
if (saved && scrollRef.current) {
196202
scrollRef.current.scrollTop = saved;
197203
}
198204
}
199-
}, [tutorialData]);
205+
}, [activeStep, tutorialData.scrollPositions]);
200206

201207
// Save scroll position on scroll
202208
const handleScroll = async () => {

0 commit comments

Comments
 (0)