Skip to content

Commit 7ba2b82

Browse files
committed
perf(landing): subscribe the hero resize listener once via a phase ref
The resize effect re-subscribed on every phase change (~30x/loop); read the current phase from a ref so the listener is added once for the component's life.
1 parent 7d1c766 commit 7ba2b82

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • apps/sim/app/(landing)/components/hero/components/hero-visual

apps/sim/app/(landing)/components/hero/components/hero-visual/hero-visual.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,16 @@ export function HeroVisual() {
913913
return () => cancelAnimationFrame(raf)
914914
}, [loaderPainting, paintFrame])
915915

916+
const phaseRef = useRef<Phase>(phase)
916917
useEffect(() => {
917-
const onResize = () => positionCursor(phase, true)
918+
phaseRef.current = phase
919+
}, [phase])
920+
921+
useEffect(() => {
922+
const onResize = () => positionCursor(phaseRef.current, true)
918923
window.addEventListener('resize', onResize)
919924
return () => window.removeEventListener('resize', onResize)
920-
}, [phase, positionCursor])
925+
}, [positionCursor])
921926

922927
useEffect(
923928
() => () => {

0 commit comments

Comments
 (0)