diff --git a/components/LazyImage.js b/components/LazyImage.js index 02f1df19952..a5437883406 100644 --- a/components/LazyImage.js +++ b/components/LazyImage.js @@ -59,7 +59,6 @@ export default function LazyImage({ useEffect(() => { const adjustedImageSrc = adjustImgSize(src, maxWidth) || defaultPlaceholderSrc - // 加载原图 const img = new Image() img.src = adjustedImageSrc @@ -68,7 +67,6 @@ export default function LazyImage({ handleImageLoaded(adjustedImageSrc) } img.onerror = handleImageError - const observer = new IntersectionObserver( entries => { entries.forEach(entry => { @@ -81,11 +79,9 @@ export default function LazyImage({ }, { rootMargin: '50px 0px' } // Adjust the rootMargin as needed to trigger the loading earlier or later ) - if (imageRef.current) { observer.observe(imageRef.current) } - return () => { if (imageRef.current) { observer.unobserve(imageRef.current) @@ -97,6 +93,7 @@ export default function LazyImage({ const imgProps = { ref: imageRef, src: currentSrc, + 'data-src': src, alt: alt, onLoad: handleThumbnailLoaded, // 缩略图加载完成 onError: handleImageError // 添加onError处理函数 @@ -118,7 +115,7 @@ export default function LazyImage({ imgProps.height = height } if (className) { - imgProps.className = className + imgProps.className = className + ' lazy-image-placeholder' } if (style) { imgProps.style = style @@ -126,6 +123,11 @@ export default function LazyImage({ if (onClick) { imgProps.onClick = onClick } + + if (!src) { + return null + } + return ( <> {/* eslint-disable-next-line @next/next/no-img-element */} @@ -136,6 +138,21 @@ export default function LazyImage({ )} + ) } diff --git a/components/LoadingCover.js b/components/LoadingCover.js index 9e24e255c71..f90ba6b3d59 100644 --- a/components/LoadingCover.js +++ b/components/LoadingCover.js @@ -1,3 +1,4 @@ +'user client' import { useGlobal } from '@/lib/global' import { useEffect, useState } from 'react' /** diff --git a/lib/global.js b/lib/global.js index a42971878bd..b9e84660efa 100644 --- a/lib/global.js +++ b/lib/global.js @@ -39,7 +39,7 @@ export function GlobalContextProvider(props) { const defaultDarkMode = NOTION_CONFIG?.APPEARANCE || APPEARANCE const [isDarkMode, updateDarkMode] = useState(defaultDarkMode === 'dark') // 默认深色模式 - const [onLoading, setOnLoading] = useState(true) // 抓取文章数据 + const [onLoading, setOnLoading] = useState(false) // 抓取文章数据 const router = useRouter() // 登录验证相关