Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
ASR Editor modal: drop virtual scroll, use content-visibility + v-memo + scrollIntoView (same fix as Speaker modal) — addresses user-reported CLS 1.60 (poor) with 20 layout shifts in the worst cluster during scroll; root cause was the same broken pattern as the speaker modal — fixed itemHeight: 44 estimated row height against variable real heights (textareas auto-resize via autoResizeTextarea, so a row with one line of sentence is ~44 px but a row with 5 lines is ~120 px), so as the user scrolls and different real heights enter the visible range, the table's total height changes (spacerBefore + visible rows real + spacerAfter is not stable), the scrollbar position recomputes, layout shifts every frame, CLS accumulates; THE FIX (3 parts); (1) styles.css gets two additions on .asr-editor-table; table-layout: fixed (required for content-visibility on <tr> — without it the browser still has to lay out every row to compute column widths, which defeats the off-screen skip) and 'content-visibility: auto; contain-intrinsic-size: auto 44px' on tbody > tr (browser skips layout + paint for off-screen rows so they don't pay the layout cost but they DO contribute their 44 px placeholder to scrollHeight, keeping the scrollbar position stable); (2) asr-editor-modal.html template drops the asrEditorSpacerBefore/After tr spacers and the asrEditorVisibleSegments iteration, iterates the FULL editingSegments array with (segment, idx), replaces segment._originalIndex with idx throughout, and adds v-memo per row so typing in one row's input/textarea doesn't fan out a re-render to the other ~4500 rows; @scroll handler no longer calls onAsrEditorScroll (no virtual range to update), only closeAllSpeakerSuggestions (keeps the user-experience parity); (3) app.modular.js utils.scrollAsrEditorToIndex switches from asrEditorVirtualScroll.scrollToIndex(index-2, 'auto') to container.querySelector([data-segment-index]) + scrollIntoView({block: 'center'}) — block: 'center' centres the row in the viewport so it lands clear of the sticky table header without needing to know the header's height; resetAsrEditorScroll just sets scrollTop=0; columns are still explicitly sized (w-40 / w-20 / w-24 + flexible sentence) so table-layout: fixed produces the same visual result as the previous auto layout; SW cache bumped to v10
Murtaza Nasir2781259fd24b
diff --git a/static/css/styles.css b/static/css/styles.cssindex 0784bd12..4e289e7e 100644--- a/static/css/styles.css+++ b/static/css/styles.css@@ -3398,6 +3398,28 @@ body {.asr-editor-table {width: 100%;border-collapse: collapse; /* Changed to collapse */+ /* table-layout: fixed lets the browser ignore row contents when+ computing column widths (instead of measuring every row to find+ the widest cell). Required for content-visibility on <tr> to+ work, because the auto algorithm forces a full table layout on+ every row to determine column widths — which defeats the whole+ point of skipping off-screen rows. Columns are explicitly sized+ in the template (w-40 / w-20 / etc.), so fixed layout produces+ the same visual result. */+ table-layout: fixed;+}++/* Skip layout + paint for off-screen ASR-editor rows. Same pattern+ used on .speaker-segment: every row stays in the DOM (so the+ scrollbar is stable and scrollIntoView lands on real positions),+ but only the on-screen ones pay the per-row layout cost.+ contain-intrinsic-size gives the browser a 44 px placeholder size+ for off-screen rows — the typical row height with one line of+ sentence text. Rows whose textarea has grown to multiple lines+ simply contribute their real height when scrolled into view. */+.asr-editor-table tbody > tr {+ content-visibility: auto;+ contain-intrinsic-size: auto 44px;}.asr-editor-table th {diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex bc43a9af..06e45253 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -2266,11 +2266,22 @@ document.addEventListener('DOMContentLoaded', async () => {// Add scrollToSegmentIndex to utils for composables that need itutils.scrollToSegmentIndex = scrollToSegmentIndex;utils.resetModalAudioState = resetModalAudioState;- utils.resetAsrEditorScroll = () => asrEditorVirtualScroll.reset();- // Scroll to the target row but offset upward so the row lands- // comfortably below the sticky table header (~2 rows of clearance)- // instead of being clipped at the top.- utils.scrollAsrEditorToIndex = (index) => asrEditorVirtualScroll.scrollToIndex(Math.max(0, index - 2), 'auto');+ utils.resetAsrEditorScroll = () => {+ if (asrEditorRef.value) asrEditorRef.value.scrollTop = 0;+ };+ // Scroll the editor table to a specific row by index. The+ // table no longer uses virtual scrolling — all rows are in+ // the DOM (with content-visibility skipping off-screen paint),+ // so this is just a real-DOM lookup + scrollIntoView using+ // measured positions. block: 'center' centres the row in the+ // viewport so it lands well clear of the sticky table header+ // without us having to know the header's height.+ utils.scrollAsrEditorToIndex = (index) => {+ const container = asrEditorRef.value;+ if (!container) return;+ const target = container.querySelector(`[data-segment-index="${index}"]`);+ if (target) target.scrollIntoView({ block: 'center', behavior: 'auto' });+ };utils.setAsrEditorScrollTop = (scrollTop) => {if (asrEditorRef.value) {asrEditorRef.value.scrollTop = scrollTop;diff --git a/static/sw.js b/static/sw.jsindex 2b606310..1a0e905c 100644--- a/static/sw.js+++ b/static/sw.js@@ -4,7 +4,7 @@// stale code even after a hard refresh. Forgetting to bump this was what// made the speaker-modal scroll fixes appear to do nothing: the SW kept// serving the broken pre-fix app.modular.js.-const CACHE_NAME = 'Speakr-cache-v9';+const CACHE_NAME = 'Speakr-cache-v10';const ASSETS_TO_CACHE = ['/','/static/offline.html',diff --git a/templates/modals/asr-editor-modal.html b/templates/modals/asr-editor-modal.htmlindex b13722b6..5d183b10 100644--- a/templates/modals/asr-editor-modal.html+++ b/templates/modals/asr-editor-modal.html@@ -73,7 +73,19 @@</div></div>- <div ref="asrEditorRef" class="flex-grow overflow-y-auto custom-scrollbar" @scroll="closeAllSpeakerSuggestions(); onAsrEditorScroll($event)">+ <!-- Editor table — renders ALL segments natively (no virtual+ scroll spacers). content-visibility: auto on each <tr>+ (set in styles.css under .asr-editor-table tbody > tr)+ lets the browser skip layout + paint for off-screen rows+ so we keep the perf win, while scrollHeight stays stable+ (placeholder size for off-screen rows = 44 px via+ contain-intrinsic-size). v-memo on each row stops Vue+ from re-rendering rows whose data didn't change when an+ unrelated row's input updates. table-layout: fixed+ (see styles.css) is required for content-visibility to+ work on table rows — without it the browser must lay out+ every row to compute column widths. -->+ <div ref="asrEditorRef" class="flex-grow overflow-y-auto custom-scrollbar" @scroll="closeAllSpeakerSuggestions()"><table class="min-w-full asr-editor-table border border-[var(--border-primary)]"><thead class="sticky top-0 z-10"><tr class="text-xs uppercase text-[var(--text-muted)]">@@ -85,18 +97,19 @@</tr></thead><tbody>- <!-- Virtual scroll spacer (top) -->- <tr v-if="asrEditorSpacerBefore > 0"><td colspan="5" :style="{ height: asrEditorSpacerBefore + 'px', padding: 0 }"></td></tr>-- <tr v-for="segment in asrEditorVisibleSegments" :key="`asr-${segment._originalIndex}-${segment.start_time}`" :data-segment-index="segment._originalIndex" :class="['hover:bg-[var(--bg-tertiary)] transition-colors border-b border-[var(--border-primary)]', { 'asr-editor-row--highlighted': asrEditorHighlightIndex === segment._originalIndex }]">+ <tr v-for="(segment, idx) in editingSegments"+ :key="`asr-${idx}-${segment.start_time}`"+ v-memo="[idx, segment.speaker, segment.start_time, segment.end_time, segment.sentence, asrEditorHighlightIndex === idx, isDropdownOpen(idx)]"+ :data-segment-index="idx"+ :class="['hover:bg-[var(--bg-tertiary)] transition-colors border-b border-[var(--border-primary)]', { 'asr-editor-row--highlighted': asrEditorHighlightIndex === idx }]"><td class="border-r border-[var(--border-primary)] align-middle"><div class="relative h-full"><div class="flex items-center h-full">- <input type="text" v-model="editingSegments[segment._originalIndex].speaker"- @input="filterSpeakerSuggestions(segment._originalIndex); openSpeakerSuggestions(segment._originalIndex)"- @focus="openSpeakerSuggestions(segment._originalIndex)"+ <input type="text" v-model="editingSegments[idx].speaker"+ @input="filterSpeakerSuggestions(idx); openSpeakerSuggestions(idx)"+ @focus="openSpeakerSuggestions(idx)"class="w-full h-full px-3 py-2.5 pr-7 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)]" />- <button type="button" @click.stop="openSpeakerSuggestions(segment._originalIndex)"+ <button type="button" @click.stop="openSpeakerSuggestions(idx)"class="absolute right-2 top-1/2 -translate-y-1/2 p-1 text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer"><i class="fas fa-chevron-down text-xs"></i></button>@@ -104,10 +117,10 @@</div><!-- Fixed position dropdown --><teleport to="body">- <div v-if="isDropdownOpen(segment._originalIndex)"+ <div v-if="isDropdownOpen(idx)"class="fixed z-[100] w-40 bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md shadow-lg max-h-48 overflow-y-auto"- :style="getDropdownPosition(segment._originalIndex)">- <div v-for="speaker in editingSegments[segment._originalIndex].filteredSpeakers" :key="speaker" @mousedown.prevent="selectSpeaker(segment._originalIndex, speaker)" class="px-3 py-2 cursor-pointer hover:bg-[var(--bg-tertiary)] text-sm">${speaker}</div>+ :style="getDropdownPosition(idx)">+ <div v-for="speaker in editingSegments[idx].filteredSpeakers" :key="speaker" @mousedown.prevent="selectSpeaker(idx, speaker)" class="px-3 py-2 cursor-pointer hover:bg-[var(--bg-tertiary)] text-sm">${speaker}</div><div @mousedown.prevent="openEditSpeakersModal" class="px-3 py-2 cursor-pointer hover:bg-[var(--bg-accent)] text-sm text-[var(--text-accent)] border-t border-[var(--border-primary)] flex items-center"><i class="fas fa-user-edit mr-2"></i> <span v-text="t('buttons.editSpeakers')"></span></div>@@ -115,31 +128,28 @@</teleport></td><td class="border-r border-[var(--border-primary)] align-middle">- <input type="number" step="0.01" v-model.number="editingSegments[segment._originalIndex].start_time" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] text-center" />+ <input type="number" step="0.01" v-model.number="editingSegments[idx].start_time" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] text-center" /></td><td class="border-r border-[var(--border-primary)] align-middle">- <input type="number" step="0.01" v-model.number="editingSegments[segment._originalIndex].end_time" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] text-center" />+ <input type="number" step="0.01" v-model.number="editingSegments[idx].end_time" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] text-center" /></td><td class="border-r border-[var(--border-primary)] align-top">- <textarea v-model="editingSegments[segment._originalIndex].sentence" rows="1" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] resize-none max-h-20 overflow-y-auto custom-scrollbar block" @input="autoResizeTextarea($event)"></textarea>+ <textarea v-model="editingSegments[idx].sentence" rows="1" class="w-full px-3 py-2.5 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)] resize-none max-h-20 overflow-y-auto custom-scrollbar block" @input="autoResizeTextarea($event)"></textarea></td><td class="px-1 text-center align-middle"><div class="flex items-center justify-center gap-1"><button @click="$refs.asrEditorAudioRef && ($refs.asrEditorAudioRef.currentTime = segment.start_time, $refs.asrEditorAudioRef.play())" class="p-1.5 rounded hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors" :title="t('help.playFromHere')"><i class="fas fa-play text-xs"></i></button>- <button @click="addSegmentBelow(segment._originalIndex)" class="p-1.5 rounded hover:bg-green-600/20 text-[var(--text-muted)] hover:text-green-500 transition-colors" :title="t('help.addSegmentBelow')">+ <button @click="addSegmentBelow(idx)" class="p-1.5 rounded hover:bg-green-600/20 text-[var(--text-muted)] hover:text-green-500 transition-colors" :title="t('help.addSegmentBelow')"><i class="fas fa-plus text-xs"></i></button>- <button @click="removeSegment(segment._originalIndex)" class="p-1.5 rounded hover:bg-red-600/20 text-[var(--text-muted)] hover:text-red-500 transition-colors" :title="t('help.deleteSegment')">+ <button @click="removeSegment(idx)" class="p-1.5 rounded hover:bg-red-600/20 text-[var(--text-muted)] hover:text-red-500 transition-colors" :title="t('help.deleteSegment')"><i class="fas fa-trash text-xs"></i></button></div></td></tr>-- <!-- Virtual scroll spacer (bottom) -->- <tr v-if="asrEditorSpacerAfter > 0"><td colspan="5" :style="{ height: asrEditorSpacerAfter + 'px', padding: 0 }"></td></tr></tbody></table><div class="py-4 flex justify-center">