From 28aecd86d351d87d5e78b8d2c6fd52896c8f3e1c Mon Sep 17 00:00:00 2001 From: Gerald Date: Sat, 29 Jul 2023 09:04:34 +0800 Subject: [PATCH] fix: avoid content flash on auto collapse (#2042) --- web/src/components/MemoContent.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/src/components/MemoContent.tsx b/web/src/components/MemoContent.tsx index bce5e690..da78d05e 100644 --- a/web/src/components/MemoContent.tsx +++ b/web/src/components/MemoContent.tsx @@ -30,22 +30,22 @@ const MemoContent: React.FC = (props: Props) => { }); const memoContentContainerRef = useRef(null); const isVisitorMode = userStore.isVisitorMode(); - const autoCollapse: boolean = isVisitorMode ? true : (userStore.state.user as User).localSetting.enableAutoCollapse; + const autoCollapse: boolean = !showFull && (isVisitorMode ? true : (userStore.state.user as User).localSetting.enableAutoCollapse); useEffect(() => { - if (showFull) { + if (!autoCollapse) { return; } if (memoContentContainerRef.current) { - const height = memoContentContainerRef.current.clientHeight; + const height = memoContentContainerRef.current.scrollHeight; if (height > MAX_EXPAND_HEIGHT) { setState({ expandButtonStatus: 0, }); } } - }, []); + }, [autoCollapse]); const handleMemoContentClick = async (e: React.MouseEvent) => { if (onMemoContentClick) { @@ -70,7 +70,7 @@ const MemoContent: React.FC = (props: Props) => {