@@ -149,8 +149,8 @@ const SegmentTimelineContainerContent = withResolvedSegment(
149149 intersectionObserver : IntersectionObserver | undefined
150150 mountedTime = 0
151151 nextPartOffset = 0
152- liveLineRefreshFrame : number | undefined
153- pendingLiveLineRefreshEvent : TimingEvent | undefined
152+ cachedLivePartOffsetRef : PartInstanceId | null = null
153+ cachedLivePartOffset = 0
154154
155155 constructor ( props : IProps & ITrackedResolvedSegmentProps ) {
156156 super ( props )
@@ -253,6 +253,8 @@ const SegmentTimelineContainerContent = withResolvedSegment(
253253 }
254254 // segment is stopping from being live
255255 if ( this . state . isLiveSegment === true && isLiveSegment === false ) {
256+ this . cachedLivePartOffsetRef = null
257+ this . cachedLivePartOffset = 0
256258 this . setState ( { isLiveSegment : false } , ( ) => {
257259 if ( Settings . autoRewindLeavingSegment ) {
258260 this . onRewindSegment ( )
@@ -355,12 +357,9 @@ const SegmentTimelineContainerContent = withResolvedSegment(
355357 if ( typeof this . props . onSegmentScroll === 'function' ) this . props . onSegmentScroll ( )
356358 }
357359
360+ this . cachedLivePartOffsetRef = null
361+ this . cachedLivePartOffset = 0
358362 this . stopLive ( )
359- if ( this . liveLineRefreshFrame !== undefined ) {
360- window . cancelAnimationFrame ( this . liveLineRefreshFrame )
361- this . liveLineRefreshFrame = undefined
362- this . pendingLiveLineRefreshEvent = undefined
363- }
364363 RundownViewEventBus . off ( RundownViewEvents . REWIND_SEGMENTS , this . onRewindSegment )
365364 RundownViewEventBus . off ( RundownViewEvents . GO_TO_PART , this . onGoToPart )
366365 RundownViewEventBus . off ( RundownViewEvents . GO_TO_PART_INSTANCE , this . onGoToPartInstance )
@@ -498,21 +497,21 @@ const SegmentTimelineContainerContent = withResolvedSegment(
498497 }
499498 }
500499
501- private flushAirLineRefresh = ( ) => {
502- this . liveLineRefreshFrame = undefined
503- const event = this . pendingLiveLineRefreshEvent
504- this . pendingLiveLineRefreshEvent = undefined
505- if ( event ) this . applyAirLineRefresh ( event )
506- }
507500
508501 private applyAirLineRefresh = ( e : TimingEvent ) => {
509502 this . setState ( ( state ) => {
510503 if ( state . isLiveSegment && state . currentLivePart ) {
511504 const currentLivePartInstance = state . currentLivePart . instance
512505
513- const partOffset =
514- ( this . context . durations ?. partDisplayStartsAt ?. [ getPartInstanceTimingId ( currentLivePartInstance ) ] || 0 ) -
515- ( this . context . durations ?. partDisplayStartsAt ?. [ getPartInstanceTimingId ( this . props . parts [ 0 ] ?. instance ) ] || 0 )
506+ // Cache the offset when the live part changes to shield it from future part updates
507+ let partOffset = this . cachedLivePartOffset
508+ if ( this . cachedLivePartOffsetRef !== currentLivePartInstance . _id ) {
509+ partOffset =
510+ ( this . context . durations ?. partDisplayStartsAt ?. [ getPartInstanceTimingId ( currentLivePartInstance ) ] || 0 ) -
511+ ( this . context . durations ?. partDisplayStartsAt ?. [ getPartInstanceTimingId ( this . props . parts [ 0 ] ?. instance ) ] || 0 )
512+ this . cachedLivePartOffsetRef = currentLivePartInstance . _id
513+ this . cachedLivePartOffset = partOffset
514+ }
516515
517516 let isExpectedToPlay = ! ! currentLivePartInstance . timings ?. plannedStartedPlayback
518517 const lastTake = currentLivePartInstance . timings ?. take
@@ -549,9 +548,7 @@ const SegmentTimelineContainerContent = withResolvedSegment(
549548 }
550549
551550 onAirLineRefresh = ( e : TimingEvent ) => {
552- this . pendingLiveLineRefreshEvent = e
553- if ( this . liveLineRefreshFrame !== undefined ) return
554- this . liveLineRefreshFrame = window . requestAnimationFrame ( this . flushAirLineRefresh )
551+ this . applyAirLineRefresh ( e )
555552 }
556553
557554 visibleChanged = ( entries : IntersectionObserverEntry [ ] ) => {
0 commit comments