Skip to content

Commit

Permalink
fix(reactive-react): fix browser crash in strict-mode async linkages …
Browse files Browse the repository at this point in the history
…scence
  • Loading branch information
janryWang committed Apr 28, 2021
1 parent 6bb3bed commit feb6487
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/reactive-react/src/hooks/useForceUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -42,5 +46,5 @@ export function useForceUpdate() {
}
}, [])

return update
return scheduler
}

0 comments on commit feb6487

Please sign in to comment.