Skip to content

Commit e56507d

Browse files
authored
Merge pull request CJY0208#232 from Cool-Star/feautures/react18-flushSync
fix: 修复在react18缓存切换时可能导致无限渲染的问题
2 parents 8c3161e + b5bd037 commit e56507d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/core/Keeper.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { PureComponent, Suspense } from 'react'
2+
import { flushSync } from 'react-dom'
23
import { get, run, nextTick, EventBus } from 'szfe-tools'
34

45
import ReactFreeze from './Freeze'
@@ -104,8 +105,10 @@ export default class Keeper extends PureComponent {
104105
// 缓存后,延迟冻结,保证各项后续处理得以进行,如关闭弹窗等
105106
clearTimeout(this.freezeTimeout)
106107
this.freezeTimeout = setTimeout(() => {
107-
this.safeSetState({
108-
freeze: true,
108+
flushSync(() => {
109+
this.safeSetState({
110+
freeze: true,
111+
})
109112
})
110113
}, 1000)
111114
}

0 commit comments

Comments
 (0)