File tree Expand file tree Collapse file tree 2 files changed +19
-14
lines changed
Expand file tree Collapse file tree 2 files changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -26,19 +26,22 @@ function App() {
2626
2727 // 当输入数据变化时,重新构建树和步骤
2828 useEffect ( ( ) => {
29- const tree = buildTreeFromArray ( inputData ) ;
30- setTreeData ( tree ) ;
31-
32- // 生成算法步骤
33- const newSteps = generateAlgorithmSteps ( tree , 600 , 350 ) ;
34- setSteps ( newSteps ) ;
35-
36- setPlaybackState ( prev => ( {
37- ...prev ,
38- currentStep : 0 ,
39- totalSteps : newSteps . length ,
40- isPlaying : false ,
41- } ) ) ;
29+ // 使用 queueMicrotask 避免在 effect 中同步调用 setState
30+ queueMicrotask ( ( ) => {
31+ const tree = buildTreeFromArray ( inputData ) ;
32+ setTreeData ( tree ) ;
33+
34+ // 生成算法步骤
35+ const newSteps = generateAlgorithmSteps ( tree , 600 , 350 ) ;
36+ setSteps ( newSteps ) ;
37+
38+ setPlaybackState ( prev => ( {
39+ ...prev ,
40+ currentStep : 0 ,
41+ totalSteps : newSteps . length ,
42+ isPlaying : false ,
43+ } ) ) ;
44+ } ) ;
4245
4346 // 停止播放
4447 if ( playIntervalRef . current ) {
Original file line number Diff line number Diff line change @@ -298,6 +298,8 @@ function getAnnotationBgColor(type: Annotation['type']): string {
298298 }
299299}
300300
301- function getAnnotationTextColor ( _type : Annotation [ 'type' ] ) : string {
301+ function getAnnotationTextColor ( type : Annotation [ 'type' ] ) : string {
302+ // 保留参数以便将来根据类型返回不同颜色
303+ void type ;
302304 return '#1a1a2e' ;
303305}
You can’t perform that action at this time.
0 commit comments