@@ -156,7 +156,7 @@ export const createRepoStateSlice: StateCreator<
156156 remoteUpdateAllPods : async ( client ) => {
157157 // The pods that haven't been inserted to the database yet
158158 const pendingPods = Object . values ( get ( ) . pods ) . filter (
159- ( pod ) => pod . dirty && pod . pending
159+ ( pod ) => ( pod . dirty || pod . dirtyPending ) && pod . pending
160160 ) ;
161161
162162 // First insert all pending pods and ignore their relationship for now
@@ -182,11 +182,17 @@ export const createRepoStateSlice: StateCreator<
182182 if ( ! pod ) return ;
183183 pod . children ?. map ( ( { id } ) => helper ( id ) ) ;
184184 if ( id !== "ROOT" ) {
185- if ( pod . dirty && ! pod . isSyncing ) {
185+ if ( ( pod . dirty || pod . dirtyPending ) && ! pod . isSyncing ) {
186186 set (
187187 produce ( ( state ) => {
188188 // FIXME when doRemoteUpdatePod fails, this will be stuck.
189189 state . pods [ id ] . isSyncing = true ;
190+ // Transfer the dirty status from dirty to dirtyPending. This is
191+ // because pod may be updated during remote syncing, and the flag
192+ // might be cleared by a successful return, causing unsaved
193+ // content.
194+ state . pods [ id ] . dirty = false ;
195+ state . pods [ id ] . dirtyPending = true ;
190196 } )
191197 ) ;
192198 try {
@@ -199,7 +205,7 @@ export const createRepoStateSlice: StateCreator<
199205 state . pods [ id ] . isSyncing = false ;
200206 // pod may be updated during remote syncing
201207 // clear dirty flag only when remote update is successful
202- if ( res ) state . pods [ id ] . dirty = false ;
208+ if ( res ) state . pods [ id ] . dirtyPending = false ;
203209 } )
204210 ) ;
205211 } catch ( e ) {
0 commit comments