fix: picture waterfall item height calculation on first render

Fix issue where picture items in waterfall view had incorrect heights on first render due to timing issues with dimension loading. Changed stableRadio calculation to use useMemo and added proper fallback for initial render.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DIYgod
2025-07-18 19:29:25 +08:00
co-authored by Claude
parent 0e456d5b73
commit 82a3537f86
@@ -149,25 +149,29 @@ const MasonryItemFixedDimensionWrapper = (
const dim = useImageDimensions(url)
const itemWidth = useMasonryItemWidth()
const itemHeight = dim ? itemWidth / dim.ratio : itemWidth
const stableRadio = useState(() => itemWidth / itemHeight || 1)[0]
const stableRadio = useMemo(() => {
return dim ? dim.ratio : 1
}, [dim])
const setItemStableRatio = useSetStableMasonryItemRatio()
const stableRadioCtx = useMasonryItemRatio(url)
useEffect(() => {
setItemStableRatio(url, stableRadio)
}, [setItemStableRatio, stableRadio, url])
if (dim) {
setItemStableRatio(url, stableRadio)
}
}, [setItemStableRatio, stableRadio, url, dim])
const finalRatio = stableRadioCtx || stableRadio
const style = useMemo(
() => ({
width: itemWidth,
height: itemWidth / stableRadioCtx! + 60,
height: itemWidth / finalRatio + 60,
}),
[itemWidth, stableRadioCtx],
[itemWidth, finalRatio],
)
if (!style.height) return null
if (!style.height || style.height === Infinity) return null
return (
<div className="relative flex h-full flex-col overflow-x-auto overflow-y-hidden" style={style}>