Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Speaker modal scroll: restore virtual scrolling (preserves #157 perf), keep fixed height + two-step scroll + smooth animation + auto-scroll on input focus — answering the question 'does content-visibility protect against the #157 4500-segment perf regression': NO, because content-visibility only saves browser paint/layout cost, not Vue's reactivity overhead (4500 mounted components × 2 buttons × handlers × dropdown v-ifs = the 2-minute pauses on edits that #157 originally reported); proper fix preserves virtual scroll which keeps ~30 components mounted, AND solves the variable-height navigation problem AND restores the polished UX the user remembered; (1) speaker-modal.html keeps virtual-scroll wiring (spacers, speakerModalVisibleSegments, @scroll handler) — only the modal-panel gets style='height: 90vh' to stop the ResizeObserver oscillation that was the actual recent regression from commit 8e1c080; (2) styles.css .speaker-segment goes back to its plain form (content-visibility removed, was a workaround for the wrong problem); (3) scrollToSegmentIndex restores the two-step dance — virtualScroll.scrollToIndex(index-3, 'auto') gets target's DOM node into the rendered window, then on two nextTicks querySelector + scrollIntoView({block:'center', behavior:'smooth'}) centres it using MEASURED position (handles variable heights) with a polished animation; 600 ms scroll-event suppression covers the smooth-scroll duration (~200-400 ms) so the in-flight visibleRange doesn't recompute and shift the destination underneath us; (4) onScroll wrappers re-added that respect the suppression flag; (5) highlightSpeakerInTranscript now ALWAYS scrolls to the nearest group rather than skipping when something happened to be already visible — earlier 'is it visible' check fought user expectation that clicking into a speaker's textbox would visibly snap to that speaker; with smooth scroll the re-centring on already-visible targets reads as polish, not as a wasted scroll; net result: clicking SPEAKER_05 textbox = smooth jump to nearest SPEAKER_05 occurrence; Next/Prev = smooth jump to next/prev occurrence; mouse-wheel = normal native scroll; 4500-segment transcripts stay fast
Murtaza Nasir8c069f52554c
diff --git a/static/css/styles.css b/static/css/styles.cssindex fd5adbdf..d2225f01 100644--- a/static/css/styles.css+++ b/static/css/styles.css@@ -1664,19 +1664,6 @@ body {.speaker-segment {margin-bottom: 1rem;transition: background-color 0.3s ease, box-shadow 0.3s ease;- /* content-visibility: auto lets the browser skip rendering this- element when it's off-screen, while keeping it in the DOM so- querySelector / scrollIntoView / sequential Tab focus all still- work against measured positions. contain-intrinsic-size gives- the browser a placeholder size to use for the off-screen- elements when computing scroll height — without it the scrollbar- would jump as elements render in. The width is auto (the- container constrains it) and the height is a generous 60 px- estimate per segment; real heights vary from ~40 px for short- sentences to several hundred for podcast paragraphs, so 60 px- is a reasonable average that keeps the scrollbar stable. */- content-visibility: auto;- contain-intrinsic-size: auto 60px;}/* Speaker run: wraps consecutive same-speaker segments so the stickydiff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 9b1be2d0..74596c51 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -2239,31 +2239,66 @@ document.addEventListener('DOMContentLoaded', async () => {// Helper to scroll to a segment by index (for speaker navigation).//- // For the speaker modal we now render every segment directly- // into the DOM (with content-visibility: auto so off-screen- // ones don't pay the paint cost) — see speaker-modal.html.- // That means scroll positioning is just querySelector +- // scrollIntoView, which uses MEASURED positions and is- // immune to variable segment heights. No virtual-scroll- // math, no spacers shifting under us, no oscillation when- // the user scrolls with the mouse wheel after a Next click.+ // Virtual scroll keeps ~30 segments mounted at a time so+ // reactivity stays cheap on 4500-segment transcripts (issue+ // #157). That's non-negotiable. The hard part is that+ // virtualScroll.scrollToIndex uses index*52 math which is+ // wrong when real segments have variable heights — a+ // single-line "Yes." is ~40 px, a long podcast paragraph+ // 600+ px. So we do a two-step dance://- // For the main transcript panel (outside the modal) the- // virtual-scroll wiring is still in place, so we fall back- // to its scrollToIndex there. That panel doesn't ship the- // Prev/Next nav buttons so the variable-height inaccuracy- // is much less visible.+ // Step 1: virtualScroll.scrollToIndex puts the target+ // index into the RENDER WINDOW (rough, fixed-height+ // math). Without this the target's DOM node+ // doesn't exist yet for the next step to find it.+ // Step 2: after Vue re-renders the new visible range,+ // querySelector for the actual DOM node and call+ // scrollIntoView({block:'center', behavior:'smooth'})+ // — this uses the element's MEASURED position so+ // variable heights stop being a problem, and the+ // browser's smooth scroll feels polished (~200 ms,+ // fast enough not to feel sluggish on rapid clicks).+ //+ // The 300 ms scroll-event suppression below stops the+ // programmatic scroll from triggering a visibleRange+ // recompute that would shift the position underneath us+ // mid-animation. Combined with the modal's fixed height+ // (style="height: 90vh" — see speaker-modal.html) which+ // stops the ResizeObserver feedback loop, this gives+ // virtual scroll back its accuracy without sacrificing+ // the perf win on long transcripts.+ let _scrollSuppressedUntil = 0;+ utils.isProgrammaticScroll = () => performance.now() < _scrollSuppressedUntil;+const scrollToSegmentIndex = (index) => {- if (showSpeakerModal.value) {- const container = speakerModalTranscriptRef.value;- if (!container) return;- const target = container.querySelector(`[data-segment-index="${index}"]`);- if (target) {- target.scrollIntoView({ block: 'center', behavior: 'auto' });- }- } else {- mainTranscriptVirtualScroll.scrollToIndex(Math.max(0, index - 3), 'auto');- }+ const inModal = showSpeakerModal.value;+ const vs = inModal ? speakerModalVirtualScroll : mainTranscriptVirtualScroll;+ const containerRef = inModal ? speakerModalTranscriptRef : mainTranscriptRef;+ if (!containerRef.value) return;++ // Smooth animation typically ~200-400ms; suppress scroll+ // event recomputes for slightly longer to be safe.+ _scrollSuppressedUntil = performance.now() + 600;++ // Step 1: rough virtual-scroll positioning so target's+ // DOM node enters the rendered range. We jump to a few+ // rows BEFORE the target so when we then smooth-scroll+ // into view, the animation is short and feels snappy.+ vs.scrollToIndex(Math.max(0, index - 3), 'auto');++ // Step 2: after Vue paints the new visible range, find+ // the real DOM node and centre it with a smooth fast+ // scroll. Two nextTicks because virtualScroll's range+ // recompute + Vue's render + browser layout pass need a+ // beat each before the target exists with measured size.+ nextTick(() => {+ nextTick(() => {+ const target = containerRef.value && containerRef.value.querySelector(`[data-segment-index="${index}"]`);+ if (target) {+ target.scrollIntoView({ block: 'center', behavior: 'smooth' });+ }+ });+ });};// Add scrollToSegmentIndex to utils for composables that need it@@ -3566,19 +3601,26 @@ document.addEventListener('DOMContentLoaded', async () => {mainTranscriptRef,asrEditorRef,asrEditorSaveFlash,- // Speaker modal renders all segments directly with- // content-visibility: auto (see speaker-modal.html), so- // these virtual-scroll exports are dead and only kept- // exported here in case some other path imports them by- // name. The template no longer uses them or @scroll.speakerModalVisibleSegments: speakerModalVirtualScroll.visibleItems,speakerModalSpacerBefore: speakerModalVirtualScroll.spacerBefore,speakerModalSpacerAfter: speakerModalVirtualScroll.spacerAfter,- onSpeakerModalScroll: speakerModalVirtualScroll.onScroll,+ // onScroll handlers are wrapped to ignore native scroll+ // events during a programmatic scroll window (set by+ // scrollToSegmentIndex). Without this, the smooth scroll+ // mid-animation triggers visibleRange recomputes that+ // shift the target position underneath us. The flag is+ // shared across both wrappers via utils.isProgrammaticScroll.+ onSpeakerModalScroll: (e) => {+ if (utils.isProgrammaticScroll && utils.isProgrammaticScroll()) return;+ speakerModalVirtualScroll.onScroll(e);+ },mainTranscriptVisibleSegments: mainTranscriptVirtualScroll.visibleItems,mainTranscriptSpacerBefore: mainTranscriptVirtualScroll.spacerBefore,mainTranscriptSpacerAfter: mainTranscriptVirtualScroll.spacerAfter,- onMainTranscriptScroll: mainTranscriptVirtualScroll.onScroll,+ onMainTranscriptScroll: (e) => {+ if (utils.isProgrammaticScroll && utils.isProgrammaticScroll()) return;+ mainTranscriptVirtualScroll.onScroll(e);+ },asrEditorVisibleSegments: asrEditorVirtualScroll.visibleItems,asrEditorSpacerBefore: asrEditorVirtualScroll.spacerBefore,asrEditorSpacerAfter: asrEditorVirtualScroll.spacerAfter,diff --git a/static/js/modules/composables/speakers.js b/static/js/modules/composables/speakers.jsindex a9a1009f..200f7d17 100644--- a/static/js/modules/composables/speakers.js+++ b/static/js/modules/composables/speakers.js@@ -604,49 +604,37 @@ export function useSpeakers(state, utils, processedTranscription) {speakerGroups.value = findSpeakerGroups(speakerId);if (speakerGroups.value.length > 0) {- // Get the current visible range from the virtual scroll+ // Pick the nearest group to whatever's currently in view+ // (so quickly cycling between speakers feels local) and+ // ALWAYS scroll to it. The previous "if it's already in+ // the visible range, don't scroll" optimization fought+ // the user's expectation: clicking into a speaker's+ // textbox should snap to that speaker's first+ // occurrence, not silently leave the viewport where it+ // happened to be. With the smooth-scroll polish in+ // scrollToSegmentIndex the scroll feels natural even+ // when the target was already on screen — it just+ // re-centres the row, which makes the highlight obvious.const visibleRange = utils.getSpeakerModalVisibleRange ? utils.getSpeakerModalVisibleRange() : null;-- if (visibleRange) {- const { start: visibleStart, end: visibleEnd } = visibleRange;- const visibleCenter = Math.floor((visibleStart + visibleEnd) / 2);-- // Check if any group is already visible- const visibleGroupIndex = speakerGroups.value.findIndex(group =>- group.startIndex >= visibleStart && group.startIndex < visibleEnd- );-- if (visibleGroupIndex !== -1) {- // A group is already visible, just set it as current (no scroll needed)- currentSpeakerGroupIndex.value = visibleGroupIndex;- } else {- // No group visible - find the nearest group to the visible center- let nearestIndex = 0;- let nearestDistance = Infinity;-- speakerGroups.value.forEach((group, index) => {- const distance = Math.abs(group.startIndex - visibleCenter);- if (distance < nearestDistance) {- nearestDistance = distance;- nearestIndex = index;- }- });-- currentSpeakerGroupIndex.value = nearestIndex;-- // Scroll to the nearest group- const nearestGroup = speakerGroups.value[nearestIndex];- if (nearestGroup && typeof nearestGroup.startIndex === 'number' && utils.scrollToSegmentIndex) {- utils.scrollToSegmentIndex(nearestGroup.startIndex);- }- }- } else {- // Fallback: no visible range available, scroll to first group- currentSpeakerGroupIndex.value = 0;- const firstGroup = speakerGroups.value[0];- if (firstGroup && typeof firstGroup.startIndex === 'number' && utils.scrollToSegmentIndex) {- utils.scrollToSegmentIndex(firstGroup.startIndex);+ const visibleCenter = visibleRange+ ? Math.floor((visibleRange.start + visibleRange.end) / 2)+ : 0;++ let nearestIndex = 0;+ let nearestDistance = Infinity;+ speakerGroups.value.forEach((group, index) => {+ const distance = Math.abs(group.startIndex - visibleCenter);+ if (distance < nearestDistance) {+ nearestDistance = distance;+ nearestIndex = index;}+ });++ currentSpeakerGroupIndex.value = nearestIndex;++ const nearestGroup = speakerGroups.value[nearestIndex];+ if (nearestGroup && typeof nearestGroup.startIndex === 'number' && utils.scrollToSegmentIndex) {+ utils.scrollToSegmentIndex(nearestGroup.startIndex);}} else {currentSpeakerGroupIndex.value = -1;diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.htmlindex 826b4bcd..b25489ad 100644--- a/templates/modals/speaker-modal.html+++ b/templates/modals/speaker-modal.html@@ -226,35 +226,38 @@</div></div>- <!-- Transcript Section.- Renders ALL segments directly into the DOM rather than- trying to virtualise the window. The previous virtual-- scroll wiring used a fixed 52 px row estimate which- fought variable-height segments (a one-line "Yes." is- ~40 px, a long podcast paragraph is 600+ px), so:- - scrollToIndex(N) landed at index*52 which was- nowhere near segment N's actual position- - the user's mouse-wheel scroll triggered an- onScroll → visibleRange recompute → spacer height- changed → scroll position drifted on its own- - rapid Next clicks oscillated for the same reason- Native rendering plus `content-visibility: auto` (set- on .speaker-segment in styles.css) gives the browser- permission to skip painting off-screen elements- without removing them from the DOM, so we keep the- paint-cost win of virtual scrolling but every- scrollIntoView / querySelector / mouse-wheel scroll- uses real measured positions. No spacers, no- onScroll handler, no oscillation. -->+ <!-- Transcript Section (virtual-scrolled for performance —+ issue #157 reported 4500+ segments causing 2+ minute+ pauses when all rendered natively, virtual scroll+ keeps ~30 segments mounted at a time so reactivity+ stays cheap).++ scrollToSegmentIndex (defined in app.modular.js) does+ a two-step dance for navigation: first virtualScroll's+ fixed-height math gets the target index into the+ RENDER WINDOW (rough), then scrollIntoView on the+ actual rendered DOM node CENTRES it using its+ measured position — that handles the case where real+ segment heights differ from the 52 px estimate+ (single "Yes." line vs 600 px podcast paragraph).+ Modal panel has a FIXED height (style=height: 90vh+ above) so containerHeight is stable; without this+ the ResizeObserver would fire on every content+ change and oscillate. --><div ref="speakerModalTranscriptRef"class="flex-grow overflow-y-auto custom-scrollbar speaker-modal-transcript min-h-0"- @click="(e) => { const t = e.target.closest('[data-start-time]')?.dataset.startTime; if (t && $refs.speakerModalAudioRef) { $refs.speakerModalAudioRef.currentTime = parseFloat(t); $refs.speakerModalAudioRef.play(); } }">+ @click="(e) => { const t = e.target.closest('[data-start-time]')?.dataset.startTime; if (t && $refs.speakerModalAudioRef) { $refs.speakerModalAudioRef.currentTime = parseFloat(t); $refs.speakerModalAudioRef.play(); } }"+ @scroll="onSpeakerModalScroll"><div v-if="processedTranscription.isJson">- <div v-for="(segment, idx) in processedTranscription.simpleSegments"- :key="getVirtualItemKey(segment, 'sm', idx)"+ <!-- Virtual scroll spacer (top) -->+ <div :style="{ height: speakerModalSpacerBefore + 'px' }"></div>++ <!-- Only render visible segments + overscan -->+ <div v-for="segment in speakerModalVisibleSegments"+ :key="getVirtualItemKey(segment, 'sm')"class="speaker-segment mb-1.5 sm:mb-2 group relative":data-start-time="segment.startTime"- :data-segment-index="idx">+ :data-segment-index="segment._originalIndex"><div class="flex items-start gap-1"><!-- Speaker tag on its own line on mobile --><span :class="[segment.color, 'speaker-tag', { 'speaker-highlight': highlightedSpeaker === segment.speakerId }]" :data-speaker-id="segment.speakerId" class="inline-block flex-shrink-0 truncate text-xs sm:text-sm font-medium w-16 sm:w-24" :title="segment.speaker">${ segment.speaker }</span>@@ -262,26 +265,29 @@<span class="word cursor-pointer hover:bg-[var(--bg-accent)] hover:text-[var(--text-accent)] rounded px-0.5 flex-1 text-xs sm:text-sm leading-relaxed">${ segment.sentence }</span><!-- Edit buttons - inline on mobile --><span class="flex items-center gap-0.5 flex-shrink-0 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity">- <button @click.stop="openSpeakerChangeDropdown(idx)" class="p-1 rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors active:scale-95" title="Change speaker">+ <button @click.stop="openSpeakerChangeDropdown(segment._originalIndex)" class="p-1 rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors active:scale-95" title="Change speaker"><i class="fas fa-user-edit text-[10px] sm:text-xs"></i></button>- <button @click.stop="openEditTextModal(idx)" class="p-1 rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors active:scale-95" title="Edit text">+ <button @click.stop="openEditTextModal(segment._originalIndex)" class="p-1 rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors active:scale-95" title="Edit text"><i class="fas fa-edit text-[10px] sm:text-xs"></i></button></span></div><!-- Speaker Change Dropdown - compact on mobile -->- <div v-if="editingSpeakerIndex === idx" @click.stop class="mt-1 p-1.5 bg-[var(--bg-tertiary)] rounded-md border border-[var(--border-primary)] shadow-lg">+ <div v-if="editingSpeakerIndex === segment._originalIndex" @click.stop class="mt-1 p-1.5 bg-[var(--bg-tertiary)] rounded-md border border-[var(--border-primary)] shadow-lg"><p class="text-[10px] text-[var(--text-muted)] mb-1">Select speaker:</p><div class="flex flex-wrap gap-1">- <button v-for="speaker in modalSpeakers" :key="speaker" @click="changeSpeaker(idx, speaker)" class="px-2 py-1 rounded-md hover:bg-[var(--bg-accent)] hover:text-[var(--text-accent)] active:scale-[0.98] transition-all flex items-center gap-1 text-xs bg-[var(--bg-secondary)]">+ <button v-for="speaker in modalSpeakers" :key="speaker" @click="changeSpeaker(segment._originalIndex, speaker)" class="px-2 py-1 rounded-md hover:bg-[var(--bg-accent)] hover:text-[var(--text-accent)] active:scale-[0.98] transition-all flex items-center gap-1 text-xs bg-[var(--bg-secondary)]"><div :class="speakerMap[speaker].color" class="w-2.5 h-2.5 rounded-full flex-shrink-0"></div><span class="truncate max-w-[60px]">${ speakerMap[speaker].name || speaker }</span></button></div></div></div>++ <!-- Virtual scroll spacer (bottom) -->+ <div :style="{ height: speakerModalSpacerAfter + 'px' }"></div></div><div v-else class="whitespace-pre-wrap text-sm text-[var(--text-primary)]">${ processedTranscription.plainText }</div></div>