diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 64f829b..5afef9f 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -90,10 +90,15 @@ export default function Index() { } useEffect(() => { + let cancelled = false + let measureTimer: ReturnType | null = null + const measureTitle = () => { + if (cancelled) return Taro.createSelectorQuery() .select('.home-header') - .boundingClientRect((rect: { top?: number; bottom?: number; height?: number } | null) => { + .boundingClientRect((rect: any) => { + if (cancelled) return if (!rect || typeof rect.bottom !== 'number' || typeof rect.height !== 'number') { const fallbackRange = Math.max(48, safe.headerPaddingTop * 0.45) titleMetricsRef.current = { @@ -113,10 +118,15 @@ export default function Index() { } Taro.nextTick(() => { - setTimeout(measureTitle, 80) + if (cancelled) return + measureTimer = setTimeout(measureTitle, 80) }) return () => { + cancelled = true + if (measureTimer !== null) { + clearTimeout(measureTimer) + } if (scrollFrameRef.current !== null) { clearTimeout(scrollFrameRef.current) }