Skip to content

Commit 815a0fb

Browse files
authored
fix(RooTips): Clear setTimeout in useEffect cleanup to prevent state updates on unmounted components (#4235)
fix: auto patch for RooTips_37
1 parent 15b3713 commit 815a0fb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

webview-ui/src/components/welcome/RooTips.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ const RooTips = ({ cycle = false }: RooTipsProps) => {
3232
useEffect(() => {
3333
if (!cycle) return
3434

35+
let timeoutId: NodeJS.Timeout | undefined = undefined
3536
const intervalId = setInterval(() => {
3637
setIsFading(true) // Start fade out
37-
setTimeout(() => {
38+
timeoutId = setTimeout(() => {
3839
setCurrentTipIndex((prevIndex) => (prevIndex + 1) % tips.length)
3940
setIsFading(false) // Start fade in
4041
}, 1000) // Fade duration
4142
}, 11000) // 10s display + 1s fade
4243

43-
return () => clearInterval(intervalId) // Cleanup on unmount
44+
return () => {
45+
clearInterval(intervalId)
46+
if (timeoutId) {
47+
clearTimeout(timeoutId)
48+
}
49+
}
4450
}, [cycle])
4551

4652
const currentTip = tips[currentTipIndex]

0 commit comments

Comments
 (0)