Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Identify Speakers modal scroll: rip out fixed-height virtual scroll, use content-visibility + scrollIntoView, ALSO restore the fixed height that broke during modal-primitive migration — actual regression bisected to commit 8e1c080 'Migrate the remaining 8 modals'; the migration replaced 'class=...h-[85vh] sm:h-[85vh]' (FIXED height) with the new .modal-panel primitive which uses 'max-height: 88vh' (MAX height); with max-height the panel shrinks to its content, so the transcript pane's clientHeight wasn't stable anymore — every render change inside it shifted the modal's overall height, which the ResizeObserver caught and recomputed visibleRange on, which rendered different items, which changed the height again — the classic feedback-loop oscillation the user was reporting; two-part fix to make this truly robust; (1) restored a fixed height on the modal panel via inline style='height: 90vh' (slightly taller than the original 85vh because the new modal-header / modal-footer chrome eats more vertical space than the old hand-rolled headers); this alone would fix the oscillation, BUT virtual scrolling with fixed itemHeight: 52 against truly variable segment heights still mis-positions scrollIntoView targets when the natural items differ wildly from 52px (long podcast paragraphs vs single 'Yes.' lines), so; (2) replaced the speaker-modal virtual scroll with native rendering of all segments + 'content-visibility: auto; contain-intrinsic-size: auto 60px' on .speaker-segment in styles.css — content-visibility is a browser-native primitive that skips the layout/paint cost of off-screen elements while keeping them in the DOM so querySelector/scrollIntoView/Tab focus all work against measured positions; gives us the perf win of virtual scrolling AND eliminates the variable-height bug AND lets the user's natural mouse-wheel scroll never trigger any JS state changes (no @scroll handler at all in the new transcript container); scrollToSegmentIndex for the modal is now just querySelector + scrollIntoView({block:'center', behavior:'auto'}) — robust, non-fragile, uses measured positions; the main transcript panel keeps its virtual scroll wiring unchanged (the bug doesn't show up there because there's no Prev/Next nav with measurable target indices)
Murtaza Nasiraa30913e8c68
diff --git a/static/css/styles.css b/static/css/styles.cssindex d2225f01..fd5adbdf 100644--- a/static/css/styles.css+++ b/static/css/styles.css@@ -1664,6 +1664,19 @@ 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 f4d1b4da..9b1be2d0 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -2239,68 +2239,31 @@ document.addEventListener('DOMContentLoaded', async () => {// Helper to scroll to a segment by index (for speaker navigation).//- // The hard problem: virtualScroll.scrollToIndex uses- // `index * itemHeight` math where itemHeight is a FIXED 52 px- // estimate. Real segments are wildly different heights — a- // single "Yes." line is ~40 px, a 20-line podcast paragraph- // is 600+ px. So if you ask to scroll to segment 50, the math- // says scrollTop = 2600, but the actual segment 50 might live- // at scrollTop = 8000 because long segments preceded it. The- // user sees the scroll land in the middle of an unrelated- // earlier speaker block. Worse, rapid Next clicks each set a- // new wrong scrollTop, the visibleRange recomputes, the new- // content height shifts the scroll position, and the whole- // thing oscillates ("vibrates").+ // 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.//- // The fix is a two-step dance:- // 1. Use the virtual scroll's fixed-height math to ROUGHLY- // position so the target's DOM node enters the rendered- // window. This is intentionally approximate.- // 2. After Vue flushes the next render, find the real- // [data-segment-index="N"] element and call- // scrollIntoView({block:'center'}). scrollIntoView uses- // the element's measured position, so variable heights- // stop being a problem. 'center' gives the user context- // above and below the highlighted row, which is the- // whole point of Prev/Next.- //- // We also suppress the onScroll handler briefly so the- // programmatic scroll doesn't bounce the visibleRange and- // re-shift our position underneath us. The flag is read by- // onSpeakerModalScroll / onMainTranscriptScroll wrappers.- let _scrollSuppressedUntil = 0;- utils.isProgrammaticScroll = () => performance.now() < _scrollSuppressedUntil;-+ // 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.const scrollToSegmentIndex = (index) => {- const inModal = showSpeakerModal.value;- const vs = inModal ? speakerModalVirtualScroll : mainTranscriptVirtualScroll;- const containerRef = inModal ? speakerModalTranscriptRef : mainTranscriptRef;- if (!containerRef.value) return;-- // Suppress onScroll handlers for the next 300 ms so the- // programmatic scroll doesn't trigger a visibleRange- // recompute that fights the destination position.- _scrollSuppressedUntil = performance.now() + 300;-- // Step 1: rough positioning via virtual scroll math so- // the target enters the render window. Offset upward by- // ~3 estimated rows so subsequent scrollIntoView has- // breathing room and doesn't have to re-scroll backwards.- vs.scrollToIndex(Math.max(0, index - 3), 'auto');-- // Step 2: after the visible range updates, find the- // actual DOM node and centre it. Two nextTicks because- // virtualScroll's range update + Vue's render pass + the- // browser's layout pass need a moment each before the- // target node exists with its real height measured.- nextTick(() => {- nextTick(() => {- const target = containerRef.value && containerRef.value.querySelector(`[data-segment-index="${index}"]`);- if (target) {- target.scrollIntoView({ block: 'center', behavior: 'auto' });- }- });- });+ 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');+ }};// Add scrollToSegmentIndex to utils for composables that need it@@ -3603,27 +3566,19 @@ 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,- // Scroll handlers are wrapped so they ignore the brief- // window after a programmatic scrollToSegmentIndex — that- // window is the one that used to cause the oscillation- // when Next/Prev was clicked rapidly: each click set a- // new scrollTop, the native scroll event fired, the- // visibleRange recomputed, layout shifted, scrollTop- // settled at a wrong spot, on and on.- onSpeakerModalScroll: (e) => {- if (utils.isProgrammaticScroll && utils.isProgrammaticScroll()) return;- speakerModalVirtualScroll.onScroll(e);- },+ onSpeakerModalScroll: speakerModalVirtualScroll.onScroll,mainTranscriptVisibleSegments: mainTranscriptVirtualScroll.visibleItems,mainTranscriptSpacerBefore: mainTranscriptVirtualScroll.spacerBefore,mainTranscriptSpacerAfter: mainTranscriptVirtualScroll.spacerAfter,- onMainTranscriptScroll: (e) => {- if (utils.isProgrammaticScroll && utils.isProgrammaticScroll()) return;- mainTranscriptVirtualScroll.onScroll(e);- },+ onMainTranscriptScroll: mainTranscriptVirtualScroll.onScroll,asrEditorVisibleSegments: asrEditorVirtualScroll.visibleItems,asrEditorSpacerBefore: asrEditorVirtualScroll.spacerBefore,asrEditorSpacerAfter: asrEditorVirtualScroll.spacerAfter,diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.htmlindex 499b2579..826b4bcd 100644--- a/templates/modals/speaker-modal.html+++ b/templates/modals/speaker-modal.html@@ -1,6 +1,15 @@-<!-- Speaker Identification Modal (design system v1) -->+<!-- Speaker Identification Modal (design system v1).+ IMPORTANT: explicit height: 85vh (was h-[85vh] in the original+ speaker-modal pre-design-system migration). The .modal-panel+ primitive uses max-height: 88vh which lets the panel SHRINK to its+ content — and when content shrinks below the viewport, the+ transcript pane's clientHeight changes too. That was the root cause+ of the scroll oscillation; the ResizeObserver fired on every+ content change, the visibleRange recomputed, different items+ rendered, height changed again, repeat. Locking the modal to a+ fixed height stops the feedback loop. --><div v-if="showSpeakerModal" @click.self="closeSpeakerModal" class="modal-overlay">- <div @click="closeSpeakerSuggestionsOnClick" class="modal-panel modal-panel--xl">+ <div @click="closeSpeakerSuggestionsOnClick" class="modal-panel modal-panel--xl" style="height: 90vh;"><div class="modal-header"><h3 class="modal-title" v-text="t('modal.identifySpeakers')"></h3><button @click="closeSpeakerModal" class="modal-close" :title="t('buttons.close')"><i class="fas fa-times"></i></button>@@ -217,21 +226,35 @@</div></div>- <!-- Transcript Section (Virtual Scrolling for performance) -->+ <!-- 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. --><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(); } }"- @scroll="onSpeakerModalScroll">+ @click="(e) => { const t = e.target.closest('[data-start-time]')?.dataset.startTime; if (t && $refs.speakerModalAudioRef) { $refs.speakerModalAudioRef.currentTime = parseFloat(t); $refs.speakerModalAudioRef.play(); } }"><div v-if="processedTranscription.isJson">- <!-- Virtual scroll spacer (top) -->- <div :style="{ height: speakerModalSpacerBefore + 'px' }"></div>-- <!-- Only render visible segments -->- <div v-for="segment in speakerModalVisibleSegments"- :key="getVirtualItemKey(segment, 'sm')"+ <div v-for="(segment, idx) in processedTranscription.simpleSegments"+ :key="getVirtualItemKey(segment, 'sm', idx)"class="speaker-segment mb-1.5 sm:mb-2 group relative":data-start-time="segment.startTime"- :data-segment-index="segment._originalIndex">+ :data-segment-index="idx"><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>@@ -239,29 +262,26 @@<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(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">+ <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"><i class="fas fa-user-edit text-[10px] sm:text-xs"></i></button>- <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">+ <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"><i class="fas fa-edit text-[10px] sm:text-xs"></i></button></span></div><!-- Speaker Change Dropdown - compact on mobile -->- <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">+ <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"><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(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)]">+ <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)]"><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>