From 78066596da9c6dc44d5e2d39ff6556c4e41045a6 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Fri, 27 Sep 2024 15:17:06 +0800 Subject: [PATCH] Revert "fix: notification memory leak (#361)" This reverts commit 6811a31a4cb9984c327c4081513149316752ef3b. --- src/NoticeList.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NoticeList.tsx b/src/NoticeList.tsx index 565d4da..1965100 100644 --- a/src/NoticeList.tsx +++ b/src/NoticeList.tsx @@ -46,7 +46,7 @@ const NoticeList: FC = (props) => { const { classNames: ctxCls } = useContext(NotificationContext); const dictRef = useRef>({}); - const latestNoticeRef = useRef(null); + const [latestNotice, setLatestNotice] = useState(null); const [hoverKeys, setHoverKeys] = useState([]); const keys = configList.map((config) => ({ @@ -72,7 +72,7 @@ const NoticeList: FC = (props) => { // Force update latest notice useEffect(() => { if (stack && dictRef.current[keys[keys.length - 1]?.key]) { - latestNoticeRef.current = dictRef.current[keys[keys.length - 1]?.key]; + setLatestNotice(dictRef.current[keys[keys.length - 1]?.key]); } }, [keys, stack]); @@ -115,7 +115,7 @@ const NoticeList: FC = (props) => { if (index > 0) { stackStyle.height = expanded ? dictRef.current[strKey]?.offsetHeight - : latestNoticeRef.current?.offsetHeight; + : latestNotice?.offsetHeight; // Transform let verticalOffset = 0; @@ -126,8 +126,8 @@ const NoticeList: FC = (props) => { const transformY = (expanded ? verticalOffset : index * offset) * (placement.startsWith('top') ? 1 : -1); const scaleX = - !expanded && latestNoticeRef.current?.offsetWidth && dictRef.current[strKey]?.offsetWidth - ? (latestNoticeRef.current?.offsetWidth - offset * 2 * (index < 3 ? index : 3)) / + !expanded && latestNotice?.offsetWidth && dictRef.current[strKey]?.offsetWidth + ? (latestNotice?.offsetWidth - offset * 2 * (index < 3 ? index : 3)) / dictRef.current[strKey]?.offsetWidth : 1; stackStyle.transform = `translate3d(${transformX}, ${transformY}px, 0) scaleX(${scaleX})`;