The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Marketing tabs prefetch ahead of the sidebar's routes
Adarsh9fdaaae0e325
diff --git a/src/components/marketing/shell.tsx b/src/components/marketing/shell.tsxindex 3c4a5e21..7315be50 100644--- a/src/components/marketing/shell.tsx+++ b/src/components/marketing/shell.tsx@@ -7,6 +7,7 @@ import { SidebarTrigger } from "@/components/ui/sidebar";import { EngineSwitch } from "@/components/studio/engine-switch";import { useEngine } from "@/lib/api";import type { Engine } from "@/lib/catalog/types";+import { useIdlePrefetch } from "@/lib/idle-prefetch";import { cn } from "@/lib/utils";import { isPlainClick, useTappedTab } from "@/lib/use-tapped-tab";@@ -43,6 +44,12 @@ export function MarketingHeader({// (with its own header) replaces this one.const [tapped, tap] = useTappedTab<SuiteTab>(active);const current = tapped ?? active;+ // The other tools are the likeliest next tap: their pages go ahead of the sidebar's routes (the "page" lane), so a busy+ // prefetch queue never leaves a tab waiting on the server.+ useIdlePrefetch(+ TABS.filter((t) => t.id !== active).map((t) => t.href),+ "page",+ );// On a phone the tabs scroll sideways: bring the current one into view.useEffect(() => {const el = nav.current?.querySelector<HTMLElement>('[aria-current="page"]');diff --git a/src/lib/idle-prefetch.ts b/src/lib/idle-prefetch.tsindex e720cd70..116340b6 100644--- a/src/lib/idle-prefetch.ts+++ b/src/lib/idle-prefetch.ts@@ -85,10 +85,9 @@ function flush() {lanes.nav.clear();for (const job of page) job.run();// Next serves a prefetch's route tree and shell (the sidebar's forty-odd routes) before any route's URL-specific part (a- // hub mode's own page), so the sidebar's rows go out only once the page's own tabs are in.- const go = () => nav.forEach((job) => job.run());- if (page.length && nav.length) afterPrefetched(page.map((job) => job.href), go);- else go();+ // hub mode's own page, a tab's page), so the sidebar's rows go out only once the page's own tabs are in and the page's+ // own prefetches (its links on screen) have gone quiet.+ if (nav.length) afterPrefetched(page.map((job) => job.href), () => nav.forEach((job) => job.run()));}/** Queues one prefetch of `href` (`run`) for the next idle moment, in its lane. Returns a cancel. */diff --git a/tests/instant-tabs.test.ts b/tests/instant-tabs.test.tsindex 54ac3d2b..993bfe70 100644--- a/tests/instant-tabs.test.ts+++ b/tests/instant-tabs.test.ts@@ -99,6 +99,8 @@ describe("other tab bars switch without a round trip", () => {const marketing = src("src/components/marketing/shell.tsx");expect(marketing).toMatch(/useTappedTab<SuiteTab>\(active\)/);expect(marketing).toMatch(/aria-current=\{t\.id === current \? "page" : undefined\}/);+ // The other tools' pages go ahead of the sidebar's routes.+ expect(marketing).toMatch(/useIdlePrefetch\(\s*TABS\.filter\(\(t\) => t\.id !== active\)\.map\(\(t\) => t\.href\),\s*"page",?\s*\)/);});it("the marketing suite's route skeletons draw its real header and tabs, the page's own tab current", () => {@@ -216,10 +218,16 @@ describe("idle prefetches: the page's own tabs go before the sidebar's routes",expect(order).toEqual(["tab music", "row image"]);});- it("with no tabs on the page, prefetches the sidebar's rows at the first idle moment", async () => {+ it("with no tabs on the page, prefetches the sidebar's rows once the page's own prefetches have gone quiet", async () => {const { queueIdlePrefetch } = await load();queueIdlePrefetch("nav", "/image", () => order.push("row image"));idle[0]();+ expect(order).toEqual([]);+ tick(300);+ answered("/gallery-card");+ tick(400);+ expect(order).toEqual([]);+ tick(200);expect(order).toEqual(["row image"]);});