Skip to content

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

fix(video-learning): defer restored material loading (#1169)

evan188199-teche3df43aaf6e1
diff --git a/web/context/WatchingContext.tsx b/web/context/WatchingContext.tsx
index 151184a88..a51ec310d 100644
--- a/web/context/WatchingContext.tsx
+++ b/web/context/WatchingContext.tsx
@@ -69,6 +69,7 @@ export function WatchingProvider({ children }: { children: ReactNode }) {
useEffect(() => {
if (typeof window === "undefined") return;
+ if (!active || material) return;
const materialId = browserStorage.readRaw("local", LAST_MATERIAL_KEY);
if (!materialId) return;
const sourceUrl = browserStorage.readRaw("local", LAST_URL_KEY) || "";
@@ -85,7 +86,7 @@ export function WatchingProvider({ children }: { children: ReactNode }) {
browserStorage.removeRaw("local", LAST_MATERIAL_KEY);
})
.finally(() => setLoading(false));
- }, [accept, t]);
+ }, [accept, active, material, t]);
const openUrl = useCallback(
async (url: string, language = "", providerOverride?: VideoProvider) => {
diff --git a/web/tests/e2e/video-learning.audit.ts b/web/tests/e2e/video-learning.audit.ts
index c540bd68f..df825f80e 100644
--- a/web/tests/e2e/video-learning.audit.ts
+++ b/web/tests/e2e/video-learning.audit.ts
@@ -9,6 +9,7 @@ test("YouTube learning survives reload and switches to Invidious without silent
let invidiousOffline = false;
let transcriptReady = true;
let transcriptRefreshCount = 0;
+ let materialRequestCount = 0;
let savedPosition = 0;
let nativeResolveCount = 0;
let nextNoteId = 1;
@@ -161,6 +162,7 @@ test("YouTube learning survives reload and switches to Invidious without silent
return json(material(body.provider_override || provider));
}
if (path === `/api/video-learning/materials/${MATERIAL_ID}`) {
+ materialRequestCount += 1;
if (provider === "invidious" && invidiousOffline) {
return json({ detail: "Invidious is offline" }, 400);
}
@@ -264,7 +266,11 @@ test("YouTube learning survives reload and switches to Invidious without silent
await expect(page.getByText("First timestamped note")).toBeVisible();
await expect(page.getByText("The first grounded concept.")).toBeVisible();
- await page.reload();
+ await page.goto("/");
+ await page.waitForTimeout(100);
+ expect(materialRequestCount).toBe(0);
+ await page.goto("/chat?capability=immersive_watching");
+ await expect.poll(() => materialRequestCount).toBe(1);
await expect(page.getByText("Timestamped lesson")).toBeVisible();
await page.getByRole("tab", { name: "Video notes" }).click();
await expect(page.getByText("First timestamped note")).toBeVisible();