@@ -113,7 +113,7 @@ export const createRepoStateSlice: StateCreator<
113113 remoteUpdateAllPods : async ( client ) => {
114114 // The pods that haven't been inserted to the database yet
115115 const pendingPods = Object . values ( get ( ) . pods ) . filter (
116- ( pod ) => pod . dirty && pod . pending
116+ ( pod ) => ( pod . dirty || pod . dirtyPending ) && pod . pending
117117 ) ;
118118
119119 // First insert all pending pods and ignore their relationship for now
@@ -139,11 +139,17 @@ export const createRepoStateSlice: StateCreator<
139139 if ( ! pod ) return ;
140140 pod . children ?. map ( ( { id } ) => helper ( id ) ) ;
141141 if ( id !== "ROOT" ) {
142- if ( pod . dirty && ! pod . isSyncing ) {
142+ if ( ( pod . dirty || pod . dirtyPending ) && ! pod . isSyncing ) {
143143 set (
144144 produce ( ( state ) => {
145145 // FIXME when doRemoteUpdatePod fails, this will be stuck.
146146 state . pods [ id ] . isSyncing = true ;
147+ // Transfer the dirty status from dirty to dirtyPending. This is
148+ // because pod may be updated during remote syncing, and the flag
149+ // might be cleared by a successful return, causing unsaved
150+ // content.
151+ state . pods [ id ] . dirty = false ;
152+ state . pods [ id ] . dirtyPending = true ;
147153 } )
148154 ) ;
149155 try {
@@ -156,7 +162,7 @@ export const createRepoStateSlice: StateCreator<
156162 state . pods [ id ] . isSyncing = false ;
157163 // pod may be updated during remote syncing
158164 // clear dirty flag only when remote update is successful
159- if ( res ) state . pods [ id ] . dirty = false ;
165+ if ( res ) state . pods [ id ] . dirtyPending = false ;
160166 } )
161167 ) ;
162168 } catch ( e ) {
0 commit comments