Description
The hero section's collision useEffect creates two setTimeout calls that are never cleaned up. If the component unmounts or collision changes rapidly, these timers can fire on unmounted components or cause stale state updates.
Files to Update
surfsense_web/components/homepage/hero-section.tsx (lines 279–294)
What to Do
Store timeout IDs and clear them in the cleanup function:
// Before
useEffect(() => {
if (collision.detected && collision.coordinates) {
setTimeout(() => {
setCollision({ detected: false, coordinates: null });
setCycleCollisionDetected(false);
if (beamRef.current) {
beamRef.current.style.opacity = "1";
}
}, 2000);
setTimeout(() => {
setBeamKey((prevKey) => prevKey + 1);
}, 2000);
}
}, [collision]);
// After
useEffect(() => {
if (!collision.detected || !collision.coordinates) return;
const timer1 = setTimeout(() => {
setCollision({ detected: false, coordinates: null });
setCycleCollisionDetected(false);
if (beamRef.current) {
beamRef.current.style.opacity = "1";
}
}, 2000);
const timer2 = setTimeout(() => {
setBeamKey((prevKey) => prevKey + 1);
}, 2000);
return () => {
clearTimeout(timer1);
clearTimeout(timer2);
};
}, [collision]);
Description
The hero section's collision
useEffectcreates twosetTimeoutcalls that are never cleaned up. If the component unmounts orcollisionchanges rapidly, these timers can fire on unmounted components or cause stale state updates.Files to Update
surfsense_web/components/homepage/hero-section.tsx(lines 279–294)What to Do
Store timeout IDs and clear them in the cleanup function: