From feb648752f63ab191927d29412c71b334941a33a Mon Sep 17 00:00:00 2001 From: janrywang Date: Wed, 28 Apr 2021 11:12:13 +0800 Subject: [PATCH] fix(reactive-react): fix browser crash in strict-mode async linkages scence --- .../reactive-react/src/hooks/useForceUpdate.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/reactive-react/src/hooks/useForceUpdate.ts b/packages/reactive-react/src/hooks/useForceUpdate.ts index 1803bf91b09..2d6da47fec0 100644 --- a/packages/reactive-react/src/hooks/useForceUpdate.ts +++ b/packages/reactive-react/src/hooks/useForceUpdate.ts @@ -10,11 +10,15 @@ export function useForceUpdate() { const unmountRef = useRef(false) const update = useCallback(() => { + if (unmountRef.current) return + setTick((tick) => { + return tick + 1 + }) + }, EMPTY_ARRAY) + + const scheduler = useCallback(() => { if (RENDER_COUNT.value === 0) { - if (unmountRef.current) return - setTick((tick) => { - return tick + 1 - }) + update() } else { if (!RENDER_QUEUE.has(update)) { RENDER_QUEUE.add(update) @@ -42,5 +46,5 @@ export function useForceUpdate() { } }, []) - return update + return scheduler }