@@ -238,7 +238,7 @@ interface NoteState {
238238 removeLocalEntry : ( relativePath : string ) => boolean
239239 moveLocalEntry : ( oldPath : string , newPath : string ) => boolean
240240 syncOpenTabsForPathChange : ( oldPath : string , newPath : string ) => Promise < void >
241- loadFileTree : ( ) => Promise < void >
241+ loadFileTree : ( options ?: { skipRemoteSync ?: boolean } ) => Promise < void >
242242 loadRemoteSyncFiles : ( ) => Promise < void >
243243 loadCollapsibleFiles : ( folderName : string ) => Promise < void >
244244 loadFolderRemoteFiles : ( folderName : string ) => Promise < void >
@@ -733,7 +733,7 @@ const useArticleStore = create<NoteState>((set, get) => ({
733733 set ( { fileTree : [ ...fileTree ] } ) // 触发重新渲染
734734 } ,
735735
736- loadFileTree : async ( ) => {
736+ loadFileTree : async ( options ) => {
737737 set ( { fileTreeLoading : true } )
738738 set ( { fileTree : [ ] } )
739739
@@ -877,7 +877,9 @@ const useArticleStore = create<NoteState>((set, get) => ({
877877 get ( ) . initVectorIndexedFiles ( )
878878
879879 // 异步加载远程同步文件(不阻塞界面)
880- get ( ) . loadRemoteSyncFiles ( )
880+ if ( ! options ?. skipRemoteSync ) {
881+ get ( ) . loadRemoteSyncFiles ( )
882+ }
881883 } ,
882884
883885 // 加载远程同步文件(后台任务)
@@ -923,8 +925,9 @@ const useArticleStore = create<NoteState>((set, get) => ({
923925 const collapsibleList = get ( ) . collapsibleList
924926 const pathsToLoad = buildRemotePathsToLoad ( collapsibleList )
925927
926- // 使用 Promise.all 并发请求所有路径的远程文件
927- const loadPromises = pathsToLoad . map ( async path => {
928+ // 目录树会在加载过程中逐步插入父级节点,因此这里必须按层级顺序加载。
929+ // 如果并发请求深层路径,远端子目录可能会在父目录节点尚未写入树时被跳过。
930+ for ( const path of pathsToLoad ) {
928931 try {
929932 let files ;
930933 switch ( primaryBackupMethod ) {
@@ -1115,14 +1118,11 @@ const useArticleStore = create<NoteState>((set, get) => ({
11151118 }
11161119 } ) ;
11171120 }
1118- set ( { fileTree : dirs } )
1121+ set ( { fileTree : [ ... dirs ] } )
11191122 }
11201123 } catch {
11211124 }
1122- } ) ;
1123-
1124- // 等待所有远程文件加载完成
1125- await Promise . all ( loadPromises )
1125+ }
11261126 } catch {
11271127 }
11281128} ,
@@ -1237,7 +1237,7 @@ const useArticleStore = create<NoteState>((set, get) => ({
12371237
12381238 // 设置子节点(可能为空)
12391239 currentFolder . children = children
1240- set ( { fileTree : cacheTree } )
1240+ set ( { fileTree : [ ... cacheTree ] } )
12411241
12421242 // 异步加载远程同步文件状态(不阻塞界面)
12431243 // 这将会填充仅存在于云端的文件
@@ -1406,7 +1406,7 @@ const useArticleStore = create<NoteState>((set, get) => ({
14061406
14071407 // 移除加载状态
14081408 currentFolder . loading = false
1409- set ( { fileTree : cacheTree } )
1409+ set ( { fileTree : [ ... cacheTree ] } )
14101410 }
14111411 }
14121412 } catch {
0 commit comments