@@ -33,6 +33,8 @@ import { convertIngestModelToPlayoutRundownWithSegments } from './commit'
3333import { convertNoteToNotification } from '../notifications/util'
3434import { PlayoutRundownModel } from '../playout/model/PlayoutRundownModel'
3535import { PieceInstance } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
36+ import { setNextPart , setNextPartFromPart } from '../playout/setNext'
37+ import { ensureNextPartIsValid } from './updateNext'
3638
3739type PlayStatus = 'previous' | 'current' | 'next'
3840type SyncedInstance = {
@@ -217,6 +219,30 @@ export async function syncChangesToPartInstances(
217219 existingPartInstance . snapshotRestore ( partInstanceSnapshot )
218220 }
219221
222+ if ( playStatus === 'next' && syncContext . hasRemovedPartInstance ) {
223+ // PartInstance was removed, so we need to remove it and re-select the next part
224+
225+ if ( playoutModel . playlist . nextPartInfo ?. manuallySelected && newPart ) {
226+ await setNextPart (
227+ context ,
228+ playoutModel ,
229+ {
230+ part : newPart ,
231+ consumesQueuedSegmentId : playoutModel . playlist . nextPartInfo . consumesQueuedSegmentId ,
232+ } ,
233+ true ,
234+ playoutModel . playlist . nextTimeOffset || 0
235+ )
236+ } else {
237+ // Clear the next part
238+ await setNextPart ( context , playoutModel , null , false , 0 )
239+ await ensureNextPartIsValid ( context , playoutModel )
240+ }
241+
242+ // We don't need to continue syncing this partInstance, as it's been replaced
243+ continue
244+ }
245+
220246 if ( playStatus === 'next' ) {
221247 existingPartInstance . recalculateExpectedDurationWithTransition ( )
222248 }
0 commit comments