diff --git a/src/app/douban/page.tsx b/src/app/douban/page.tsx index 2a4e8f0..b7d9ee5 100644 --- a/src/app/douban/page.tsx +++ b/src/app/douban/page.tsx @@ -30,6 +30,7 @@ function DoubanPageClient() { const [selectorsReady, setSelectorsReady] = useState(false); const observerRef = useRef(null); const loadingRef = useRef(null); + const contentRef = useRef(null); const debounceTimeoutRef = useRef(null); // 用于存储最新参数值的 refs @@ -598,6 +599,34 @@ function DoubanPageClient() { }; }, [hasMore, isLoadingMore, loading]); + // 首屏如果未被撑满,仅在第一页时额外请求一次下一页 + useEffect(() => { + if ( + loading || + !selectorsReady || + isLoadingMore || + !hasMore || + doubanData.length === 0 || + currentPage !== 0 + ) { + return; + } + + const rafId = window.requestAnimationFrame(() => { + const contentEl = contentRef.current; + if (!contentEl) return; + + const rect = contentEl.getBoundingClientRect(); + const preloadThreshold = window.innerHeight + 120; + + if (rect.bottom < preloadThreshold) { + setCurrentPage(1); + } + }); + + return () => window.cancelAnimationFrame(rafId); + }, [loading, selectorsReady, isLoadingMore, hasMore, doubanData.length, currentPage]); + // 处理选择器变化 const handlePrimaryChange = useCallback( (value: string) => { @@ -781,7 +810,7 @@ function DoubanPageClient() { {/* 内容展示区域 */} -
+
{/* 内容网格 */}
{loading || !selectorsReady