Skip to content

Commit 83c38f1

Browse files
committed
fix: let UI settle before testing for segment being in view
1 parent e52379b commit 83c38f1

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/webui/src/client/ui/SegmentTimeline/SegmentTimelineContainer.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ const SegmentTimelineContainerContent = withResolvedSegment(
145145
declare context: React.ContextType<typeof RundownTimingProviderContext>
146146

147147
isVisible: boolean
148+
visibilityChangeTimeout: NodeJS.Timeout | undefined
148149
rundownCurrentPartInstanceId: PartInstanceId | null = null
149150
timelineDiv: HTMLDivElement | null = null
150151
intersectionObserver: IntersectionObserver | undefined
@@ -535,12 +536,20 @@ const SegmentTimelineContainerContent = withResolvedSegment(
535536
}
536537

537538
visibleChanged = (entries: IntersectionObserverEntry[]) => {
538-
if (entries[0].intersectionRatio < 0.99 && !isMaintainingFocus() && Date.now() - this.mountedTime > 2000) {
539-
if (typeof this.props.onSegmentScroll === 'function') this.props.onSegmentScroll()
540-
this.isVisible = false
541-
} else {
542-
this.isVisible = true
539+
// Add a small debounce to ensure UI has settled before checking
540+
if (this.visibilityChangeTimeout) {
541+
clearTimeout(this.visibilityChangeTimeout)
543542
}
543+
544+
this.visibilityChangeTimeout = setTimeout(() => {
545+
if (entries[0].intersectionRatio < 0.99 && !isMaintainingFocus() && Date.now() - this.mountedTime > 2000) {
546+
console.log('Segment out of view :', this.props.segmentId)
547+
if (typeof this.props.onSegmentScroll === 'function') this.props.onSegmentScroll()
548+
this.isVisible = false
549+
} else {
550+
this.isVisible = true
551+
}
552+
}, 2000)
544553
}
545554

546555
startLive = () => {

0 commit comments

Comments
 (0)