@@ -2,7 +2,7 @@ import {type Action, type SanityClient} from '@sanity/client'
2
2
import { type Mutation } from '@sanity/mutator'
3
3
import { type SanityDocument } from '@sanity/types'
4
4
import { omit } from 'lodash'
5
- import { EMPTY , from , merge , type Observable , Subject } from 'rxjs'
5
+ import { EMPTY , from , merge , type Observable } from 'rxjs'
6
6
import { filter , map , mergeMap , share , take , tap } from 'rxjs/operators'
7
7
8
8
import {
@@ -65,7 +65,7 @@ export interface Pair {
65
65
transactionsPendingEvents$ : Observable < PendingMutationsEvent >
66
66
published : DocumentVersion
67
67
draft : DocumentVersion
68
- complete : ( ) => void
68
+ _keepalive : Observable < never >
69
69
}
70
70
71
71
function setVersion < T > ( version : 'draft' | 'published' ) {
@@ -204,10 +204,7 @@ export function checkoutPair(
204
204
) : Pair {
205
205
const { publishedId, draftId} = idPair
206
206
207
- const listenerEventsConnector = new Subject < ListenerEvent > ( )
208
- const listenerEvents$ = getPairListener ( client , idPair , pairListenerOptions ) . pipe (
209
- share ( { connector : ( ) => listenerEventsConnector } ) ,
210
- )
207
+ const listenerEvents$ = getPairListener ( client , idPair , pairListenerOptions ) . pipe ( share ( ) )
211
208
212
209
const reconnect$ = listenerEvents$ . pipe (
213
210
filter ( ( ev ) => ev . type === 'reconnect' ) ,
@@ -255,6 +252,8 @@ export function checkoutPair(
255
252
consistency$ : published . consistency$ ,
256
253
remoteSnapshot$ : published . remoteSnapshot$ . pipe ( map ( setVersion ( 'published' ) ) ) ,
257
254
} ,
258
- complete : ( ) => listenerEventsConnector . complete ( ) ,
255
+ // Use this to keep the mutation pipeline active.
256
+ // It won't ever emit any events, but it will prevent the eventsource connection from completing for as long as it is subscribed to
257
+ _keepalive : commits$ . pipe ( mergeMap ( ( ) => EMPTY ) ) ,
259
258
}
260
259
}
0 commit comments