From 450620422f9c69e9d6362401710abd78dc734ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 19 Dec 2024 17:39:40 +0800 Subject: [PATCH] fix: suspense repeat trigger --- src/hooks/useStatus.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/hooks/useStatus.ts b/src/hooks/useStatus.ts index b040028..73014ef 100644 --- a/src/hooks/useStatus.ts +++ b/src/hooks/useStatus.ts @@ -191,8 +191,17 @@ export default function useStatus( activeRef.current = active; // ============================ Status ============================ + const visibleRef = useRef(null); + // Update with new status useIsomorphicLayoutEffect(() => { + // When use Suspense, the `visible` will repeat trigger, + // But not real change of the `visible`, we need to skip it. + // https://github.com/ant-design/ant-design/issues/44379 + if (mountedRef.current && visibleRef.current === visible) { + return; + } + setAsyncVisible(visible); const isMounted = mountedRef.current; @@ -232,6 +241,8 @@ export default function useStatus( // Set back in case no motion but prev status has prepare step setStatus(STATUS_NONE); } + + visibleRef.current = visible; }, [visible]); // ============================ Effect ============================