Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Speaker modal: drop hydration split, mount all rows fully so speaker-highlight is consistent — user reported intermittent highlight glow when navigating speakers; the cause was the hydrated/placeholder template split I added for perf — both branches DID carry the speaker-highlight class binding, but the interaction between v-memo's per-row cache and IntersectionObserver promoting/demoting rows mid-selection produced rows where the cached render output didn't reflect the new highlightedSpeaker state until something else triggered a re-render; the simpler fix is to drop the split — speaker modal rows are light enough (just text spans + hover button shells + a conditional dropdown) that mounting all 2500 in Vue isn't catastrophic, and content-visibility: auto on .speaker-segment in styles.css still skips the browser's paint cost for off-screen rows so most of the perf win is preserved; removes the _makeRowHydrator factory invocations + IntersectionObserver wiring, keeps hydrateAsrEditorRow / hydrateSpeakerModalRow as no-op stubs in case any leftover template references call them; the consequence is a slightly higher initial modal-open cost on very long transcripts (a few hundred ms for 2500 rows) but the speaker-highlight glow now works consistently for every segment of the selected speaker regardless of viewport position or scroll history

Murtaza Nasirb62e1a5075da
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 2a1b8dbf..dbb3f9b4 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -1201,71 +1201,19 @@ 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 SPEAKER modal long transcript
- // pane (declared above as speakerModalHydratedRows). The
- // factory creates an IntersectionObserver against the
- // scrollable container. 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 regardless of
- // transcript length. A row is never dehydrated while it
- // contains document.activeElement, so editing mid-scroll
- // never yanks an input away.
- //
- // The ASR editor uses a different approach (fixed-height
- // virtual scrolling) because its rows are spreadsheet-like
- // — uniform single-line inputs + a textarea capped at
- // max-h-20. Variable-height tricks aren't worth the CLS
- // cost there.
- // -------------------------------------------------------------
- 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 _speakerModalHydrator = _makeRowHydrator(speakerModalTranscriptRef, speakerModalHydratedRows);
- const hydrateSpeakerModalRow = _speakerModalHydrator.hydrate;
- watch(showSpeakerModal, (open) => {
- if (open) nextTick(() => _speakerModalHydrator.setup());
- else _speakerModalHydrator.teardown();
- });
- // ASR editor uses virtual scroll; no hydration wiring needed.
- // Keep hydrateAsrEditorRow as a no-op for any leftover refs.
+ // Lazy-hydration was previously wired for both modals but
+ // (a) the ASR editor went back to virtual scrolling (uniform
+ // row heights make fixed-itemHeight the right tool) and
+ // (b) the speaker modal hydration scheme made the speaker
+ // highlight glow intermittent because the hydrated/placeholder
+ // template split interacted badly with v-memo as rows
+ // promoted/demoted mid-selection. Speaker modal now mounts
+ // all rows in full; content-visibility: auto on .speaker-segment
+ // still skips paint for off-screen rows so most of the perf
+ // win is preserved. Keep the hydrate stubs as no-ops in case
+ // any leftover template reference still calls them.
const hydrateAsrEditorRow = () => {};
+ const hydrateSpeakerModalRow = () => {};
// --- Computed properties needed by composables ---
const isMobileScreen = computed(() => windowWidth.value < 1024);
diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.html
index a34c9323..5d5c51d1 100644
--- a/templates/modals/speaker-modal.html
+++ b/templates/modals/speaker-modal.html
@@ -276,66 +276,55 @@
style="flex: 1 1 auto; min-height: 0; overflow-y: auto;"
@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">
+ <!-- Each segment is mounted in full (no hydrated/
+ placeholder split). The hydration scheme was
+ introduced for perf but made speaker-highlight
+ intermittent because the two template branches
+ interacted oddly with v-memo when the
+ IntersectionObserver promoted/demoted rows
+ mid-selection. The browser still skips paint
+ for off-screen rows via content-visibility:
+ auto on .speaker-segment (see styles.css), so
+ we keep most of the perf win without the
+ rendering regressions. v-memo per row stops
+ Vue from re-rendering unrelated rows when
+ one row's data changes. -->
<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, speakerModalHydratedRows.has(idx)]"
+ v-memo="[idx, segment.speakerId, segment.speaker, segment.sentence, highlightedSpeaker === segment.speakerId, editingSpeakerIndex === idx]"
class="speaker-segment group relative"
:data-start-time="segment.startTime"
:data-segment-index="idx">
- <!-- 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 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 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>
</div>
- </template>
+ </div>
</div>
</div>
<div v-else class="whitespace-pre-wrap text-sm text-[var(--text-primary)]">${ processedTranscription.plainText }</div>