Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Bounded lazy-hydration for ASR editor + speaker modal rows — addresses the 1408 ms INP / 142k DOM nodes / 71% CPU regressions the user hit at 2500 segments; content-visibility skipped the BROWSER's paint cost but Vue still mounted every row's reactive bindings; THE FIX is a generic _makeRowHydrator factory + IntersectionObserver that promotes a row to its full interactive form (inputs, buttons, dropdown teleport, edit handlers) ONLY when it's near the viewport (within 600 px above and below), and DEMOTES the row back to a lightweight static placeholder when it scrolls out — bounded membership so the hydrated set stays around one viewport's worth (~50-100 rows) regardless of transcript length; without the dehydration step the user's scroll top→bottom would gradually leave every row hydrated and re-introduce the regression; rows containing document.activeElement are never dehydrated so the user typing into an input mid-scroll never gets it yanked away; ASR editor placeholder is 4 read-only <td>s rendering segment fields, hydrated version has the 4 v-models + dropdown teleport + 3 action buttons; speaker-modal placeholder is the speaker tag + text spans (no hover buttons, no edit dropdown), hydrated version has the hover edit buttons + change-speaker dropdown; both modals' v-memo dependency lists now include the hydratedRows.has(idx) check so promotion/demotion correctly triggers re-render; speaker modal also keeps a row hydrated whenever editingSpeakerIndex === idx so an open dropdown survives a scroll; one shared factory keeps both modals' implementations identical (different containerRef + hydratedRows) for clarity
Murtaza Nasir4787ec88c134
diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 06e45253..8b0b3bf8 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -557,6 +557,12 @@ document.addEventListener('DOMContentLoaded', async () => {const showSharesListModal = ref(false);const showTextEditorModal = ref(false);const showAsrEditorModal = ref(false);+ // Placeholder refs — the actual hydration Sets are wired up+ // later (after speakerModalTranscriptRef and asrEditorRef are+ // declared). Declared here so the rest of this state block+ // can reference them without temporal-dead-zone errors.+ const asrEditorHydratedRows = ref(new Set());+ const speakerModalHydratedRows = ref(new Set());const showCustomizeSummaryModal = ref(false);const customizeSummaryPrompt = ref('');const customizeSummaryMode = ref('append'); // 'append' | 'replace'@@ -1195,6 +1201,78 @@ document.addEventListener('DOMContentLoaded', async () => {const asrEditorSaveFlash = ref(false); // Brief "Saved" indicator after Save (without close)const asrEditorHighlightIndex = ref(null); // Segment index briefly highlighted after double-click open+ // -------------------------------------------------------------+ // Lazy-hydration wiring for the ASR editor + speaker modal+ // long lists (declared above as asrEditorHydratedRows /+ // speakerModalHydratedRows). The factory creates one+ // IntersectionObserver per pane. Rows entering the watch+ // region (viewport ± 600 px) get added to the hydrated Set;+ // rows leaving get REMOVED — bounded membership so the+ // hydrated count stays around one viewport's worth (~50–100+ // rows) regardless of transcript length. Without bounded+ // dehydration, scrolling top → bottom would gradually+ // promote every row and re-introduce the 1400 ms INP /+ // 142k DOM nodes regression we saw at 2500 segments. A row+ // is never dehydrated while it contains+ // document.activeElement, so the user editing an input+ // mid-scroll never gets it yanked away.+ //+ // Same factory is shared between modals; each gets its own+ // observer + Set so they can run independently. Modal-open /+ // close cycles re-set up / tear down via watch on+ // showAsrEditorModal / showSpeakerModal.+ // -------------------------------------------------------------+ const _makeRowHydrator = (containerRef, hydratedRef, options = {}) => {+ const observer = { current: null };+ const rootMargin = options.rootMargin || '600px 0px 600px 0px';+ const setup = () => {+ if (observer.current) { observer.current.disconnect(); observer.current = null; }+ if (!containerRef.value) return;+ observer.current = new IntersectionObserver((entries) => {+ let changed = false;+ const next = new Set(hydratedRef.value);+ for (const entry of entries) {+ const idx = parseInt(entry.target.dataset.segmentIndex, 10);+ if (Number.isNaN(idx)) continue;+ if (entry.isIntersecting) {+ if (!next.has(idx)) { next.add(idx); changed = true; }+ } else {+ if (entry.target.contains(document.activeElement)) continue;+ if (next.has(idx)) { next.delete(idx); changed = true; }+ }+ }+ if (changed) hydratedRef.value = next;+ }, { root: containerRef.value, rootMargin });+ nextTick(() => {+ const rows = containerRef.value.querySelectorAll('[data-segment-index]');+ rows.forEach(r => observer.current.observe(r));+ });+ };+ const teardown = () => {+ if (observer.current) { observer.current.disconnect(); observer.current = null; }+ hydratedRef.value = new Set();+ };+ const hydrate = (idx) => {+ if (hydratedRef.value.has(idx)) return;+ const next = new Set(hydratedRef.value);+ next.add(idx);+ hydratedRef.value = next;+ };+ return { setup, teardown, hydrate };+ };+ const _asrEditorHydrator = _makeRowHydrator(asrEditorRef, asrEditorHydratedRows);+ const hydrateAsrEditorRow = _asrEditorHydrator.hydrate;+ watch(showAsrEditorModal, (open) => {+ if (open) nextTick(() => _asrEditorHydrator.setup());+ else _asrEditorHydrator.teardown();+ });+ const _speakerModalHydrator = _makeRowHydrator(speakerModalTranscriptRef, speakerModalHydratedRows);+ const hydrateSpeakerModalRow = _speakerModalHydrator.hydrate;+ watch(showSpeakerModal, (open) => {+ if (open) nextTick(() => _speakerModalHydrator.setup());+ else _speakerModalHydrator.teardown();+ });+// --- Computed properties needed by composables ---const isMobileScreen = computed(() => windowWidth.value < 1024);@@ -1513,7 +1591,7 @@ document.addEventListener('DOMContentLoaded', async () => {// ModalsshowEditModal, showDeleteModal, showEditTagsModal, selectedNewTagId, tagSearchFilter,showReprocessModal, showResetModal, showSpeakerModal, speakerModalTab, speakerModalVideoCollapsed, toggleSpeakerModalVideo, showShareModal, showSharesListModal,- showTextEditorModal, showAsrEditorModal, showCustomizeSummaryModal, customizeSummaryPrompt, customizeSummaryMode, editingRecording, editingTranscriptionContent,+ showTextEditorModal, showAsrEditorModal, asrEditorHydratedRows, hydrateAsrEditorRow, speakerModalHydratedRows, hydrateSpeakerModalRow, showCustomizeSummaryModal, customizeSummaryPrompt, customizeSummaryMode, editingRecording, editingTranscriptionContent,editingSegments, availableSpeakers, showEditSpeakersModal, editingSpeakersList,databaseSpeakers, editingSpeakerSuggestions,showEditParticipantsModal, editingParticipantsList, editingParticipantSuggestions, allParticipants,diff --git a/templates/modals/asr-editor-modal.html b/templates/modals/asr-editor-modal.htmlindex 5d183b10..9805fa4e 100644--- a/templates/modals/asr-editor-modal.html+++ b/templates/modals/asr-editor-modal.html@@ -99,56 +99,78 @@<tbody><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)]"+ v-memo="[idx, segment.speaker, segment.start_time, segment.end_time, segment.sentence, asrEditorHighlightIndex === idx, asrEditorHydratedRows.has(idx), isDropdownOpen(idx)]":data-segment-index="idx"+ @focusin="hydrateAsrEditorRow(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[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(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>+ <!-- Hydrated (interactive) version: only mounted once+ the IntersectionObserver in app.modular.js has+ promoted this row, or the user has focused into+ it via @focusin. Carries all the v-models,+ event handlers, and the dropdown teleport. -->+ <template v-if="asrEditorHydratedRows.has(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[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(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>+ </div></div>- </div>- <!-- Fixed position dropdown -->- <teleport to="body">- <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(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>+ <teleport to="body">+ <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(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></div>+ </teleport>+ </td>+ <td class="border-r border-[var(--border-primary)] align-middle">+ <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[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[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(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(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>- </teleport>- </td>- <td class="border-r border-[var(--border-primary)] align-middle">- <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[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[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(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(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>+ </td>+ </template>+ <!-- Placeholder version for off-screen rows: just+ 4 read-only `<td>`s rendering the current+ values. No v-model, no event handlers, no+ dropdown teleport — cheap to mount. The+ padding intentionally matches the hydrated+ version's input padding (px-3 py-2.5) so+ promotion in place doesn't cause a visible+ layout shift. -->+ <template v-else>+ <td class="border-r border-[var(--border-primary)] align-middle px-3 py-2.5 text-sm text-[var(--text-primary)] truncate">${ segment.speaker }</td>+ <td class="border-r border-[var(--border-primary)] align-middle px-3 py-2.5 text-sm text-[var(--text-primary)] text-center">${ segment.start_time }</td>+ <td class="border-r border-[var(--border-primary)] align-middle px-3 py-2.5 text-sm text-[var(--text-primary)] text-center">${ segment.end_time }</td>+ <td class="border-r border-[var(--border-primary)] align-top px-3 py-2.5 text-sm text-[var(--text-primary)]">${ segment.sentence }</td>+ <td></td>+ </template></tr></tbody></table>diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.htmlindex abe436ec..8917bd0c 100644--- a/templates/modals/speaker-modal.html+++ b/templates/modals/speaker-modal.html@@ -268,41 +268,64 @@<div v-if="processedTranscription.isJson"><div v-for="(segment, idx) in processedTranscription.simpleSegments":key="segment.startTime + '-' + idx"- v-memo="[idx, segment.speakerId, segment.speaker, segment.sentence, highlightedSpeaker === segment.speakerId, editingSpeakerIndex === idx]"+ v-memo="[idx, segment.speakerId, segment.speaker, segment.sentence, highlightedSpeaker === segment.speakerId, editingSpeakerIndex === idx, speakerModalHydratedRows.has(idx)]"class="speaker-segment group relative":data-start-time="segment.startTime":data-segment-index="idx">- <div class="flex items-start gap-2">- <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>- <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>- <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="btn btn--icon btn--sm" title="Change speaker">- <i class="fas fa-user-edit text-[10px]"></i>- </button>- <button @click.stop="openEditTextModal(idx)" class="btn btn--icon btn--sm" title="Edit text">- <i class="fas fa-edit text-[10px]"></i>- </button>- </span>- </div>-- <div v-if="editingSpeakerIndex === idx"- @click.stop- class="surface-raised"- style="margin-top: var(--sp-2); padding: var(--sp-2);">- <p class="t-label" style="margin-bottom: var(--sp-2);">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-tertiary)]">- <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>+ <!-- Hydrated (full) version: includes hover-only+ edit/change-speaker buttons and the+ conditional change-speaker dropdown. Mounted+ only when the IntersectionObserver promotes+ the row (it's near the viewport). The+ placeholder below is what shows for+ off-screen rows. -->+ <template v-if="speakerModalHydratedRows.has(idx) || editingSpeakerIndex === idx">+ <div class="flex items-start gap-2">+ <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>+ <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>+ <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="btn btn--icon btn--sm" title="Change speaker">+ <i class="fas fa-user-edit text-[10px]"></i>+ </button>+ <button @click.stop="openEditTextModal(idx)" class="btn btn--icon btn--sm" title="Edit text">+ <i class="fas fa-edit text-[10px]"></i>+ </button>+ </span></div>- </div>+ <div v-if="editingSpeakerIndex === idx"+ @click.stop+ class="surface-raised"+ style="margin-top: var(--sp-2); padding: var(--sp-2);">+ <p class="t-label" style="margin-bottom: var(--sp-2);">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-tertiary)]">+ <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>+ </template>+ <!-- Placeholder (lightweight) version for+ off-screen rows: same speaker pill + text+ spans, no hover button shells, no edit+ dropdown. The natural height matches the+ hydrated version's height with no edit+ dropdown open, so promotion in place+ doesn't shift the layout. -->+ <template v-else>+ <div class="flex items-start gap-2">+ <span :class="[segment.color, 'speaker-tag', { 'speaker-highlight': highlightedSpeaker === 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>+ <span class="flex-1 text-xs sm:text-sm leading-relaxed text-[var(--text-primary)]">${ segment.sentence }</span>+ </div>+ </template></div></div><div v-else class="whitespace-pre-wrap text-sm text-[var(--text-primary)]">${ processedTranscription.plainText }</div>