Skip to content

Commit

Permalink
Merge pull request #47 from retejs/fix/flush-sync-warning
Browse files Browse the repository at this point in the history
fix: run flushSync in microtask
  • Loading branch information
Ni55aN authored Oct 24, 2023
2 parents 5a92d81 + fa2ba02 commit 4c8e4a1
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,7 @@ export function syncFlush() {
return {
apply(f: () => void) {
if (ready.current) {
try {
flushSync(f)
} catch (error) {
const message = error ? (error as Error).message : null

if (message && (
message.includes('flushSync was called from inside a lifecycle method')
|| message.includes('React error #187')
)) {
f()
return
}
throw error
}
queueMicrotask(() => flushSync(f))
} else {
f()
}
Expand Down

0 comments on commit 4c8e4a1

Please sign in to comment.