Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

perf(reading): defer EPUB and video marks until needed

Bingxi Zhao (Frank)0d8f4a4c873a
diff --git a/web/components/reading/ReaderPane.tsx b/web/components/reading/ReaderPane.tsx
index 271e304d8..71bed03e6 100644
--- a/web/components/reading/ReaderPane.tsx
+++ b/web/components/reading/ReaderPane.tsx
@@ -1,5 +1,6 @@
"use client";
+import dynamic from "next/dynamic";
import { browserStorage } from "@/shared/storage";
import Tooltip from "@/shared/ui/Tooltip";
@@ -40,7 +41,6 @@ import {
import { AnnotationList } from "./AnnotationList";
import { AnnotationPopover, type PopoverAiAction } from "./AnnotationPopover";
import { passagePrompts } from "@/lib/reading-passage-prompts";
-import { EpubDocumentView } from "./EpubDocumentView";
import {
PdfDocumentView,
type JumpRequest,
@@ -69,6 +69,20 @@ import {
type ReadingLocationHistory,
} from "@/lib/reading-location-history";
+function EpubLoading() {
+ const { t } = useTranslation();
+ return (
+ <div role="status" aria-label={t("Loading")} className="flex h-full items-center justify-center">
+ <Loader2 aria-hidden="true" className="h-5 w-5 animate-spin text-[var(--muted-foreground)]" />
+ </div>
+ );
+}
+
+const EpubDocumentView = dynamic(
+ () => import("./EpubDocumentView").then(module => module.EpubDocumentView),
+ { ssr: false, loading: EpubLoading },
+);
+
/** Event the reader dispatches to prefill the composer from a selection. */
export const READER_ASK_EVENT = "dt:reader-ask";
const AUTO_JUMP_KEY = "dt.reader.autoJump";
diff --git a/web/components/watching/WatchingPane.tsx b/web/components/watching/WatchingPane.tsx
index 91dd2f56a..591ef59f0 100644
--- a/web/components/watching/WatchingPane.tsx
+++ b/web/components/watching/WatchingPane.tsx
@@ -1,5 +1,6 @@
'use client'
+import dynamic from 'next/dynamic'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import {
AlertTriangle,
@@ -54,10 +55,23 @@ import {
} from '@/lib/video-learning-marks'
import { stepTranscriptMatch, transcriptMatchIndexes } from '@/lib/transcript-search'
import { videoTimeFromHref } from '@/lib/watching-citations'
-import { WatchingMarksPanel } from './WatchingMarksPanel'
import { WatchingPlayer } from './WatchingPlayer'
import { transcriptFollowScrollTop } from '@/lib/transcript-follow'
+function MarksLoading() {
+ const { t } = useTranslation()
+ return (
+ <div role="status" aria-label={t('Loading')} className="flex justify-center py-4">
+ <Loader2 aria-hidden="true" className="h-4 w-4 animate-spin text-[var(--muted-foreground)]" />
+ </div>
+ )
+}
+
+const WatchingMarksPanel = dynamic(
+ () => import('./WatchingMarksPanel').then(module => module.WatchingMarksPanel),
+ { ssr: false, loading: MarksLoading },
+)
+
export const WATCHING_ASK_EVENT = 'dt:watching-ask'
type WatchTab = 'transcript' | 'notes' | 'marks'