fix(RooTips): Clear setTimeout in useEffect cleanup to prevent state updates on unmounted components #4235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR for RooTips setTimeout Leak (RooTips_37)
This PR addresses the uncleaned
setTimeoutin theRooTipscomponent, as identified inleak-report/guaranteed/RooTips_37.md.Description
The
useEffecthook inRooTips.tsxcorrectly clears itssetIntervalbut fails to clear asetTimeoutthat is scheduled within the interval's callback. If the component unmounts or thecycleprop changes while thissetTimeoutis pending, it can lead to attempts to update state on an unmounted component.This patch implements the suggested fix from the leak report: storing the
timeoutIdfromsetTimeoutand clearing it in theuseEffectcleanup function.Related Bug Report
#4234
Changes
webview-ui/src/components/welcome/RooTips.tsx:timeoutIdwithin theuseEffectscope.setTimeouttotimeoutId.clearTimeout(timeoutId)to theuseEffectcleanup function.How to Test
RooTipscomponent withcycle={true}.setTimeoutis scheduled.RooTipscomponent (or change thecycleprop) before the 1-second fade duration (controlled by thesetTimeout) completes.Important
Fixes uncleaned
setTimeoutinRooTips.tsxto prevent state updates on unmounted components.setTimeoutinRooTips.tsxby storingtimeoutIdand clearing it inuseEffectcleanup.cycleprop changes or component unmounts.RooTipswithcycle={true}and unmount beforesetTimeoutcompletes to ensure no React warnings.This description was created by
for 8cb42dd. You can customize this summary. It will automatically update as commits are pushed.
Closes: #4234