commit ca4d88137736c80d97098ec0ca04becaa52d0249
parent a22e13e9f105338db28a7cdfcf30048150fa17a4
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 01:50:45 -0500
dashboard: the shell is sent at once; the live half and the channels table stream in
The page awaited every read before its first byte: every channel's
config and report, the live job list (which may count a job's progress
off the disk), the sync state, the alerts. It now starts the two reads
and hands them to the cockpit as promises; the live half (pipeline band,
Needs work) and the channels table each read theirs inside their own
Suspense boundary, behind a skeleton sized by counts known beforehand
(live jobs from memory, channels from one readdir). A refresh is a
transition, so a section on screen stays until its new render is ready.
Recent changes: the whole changelog (900 KB here) was handed to the
client as a string, doubled in the document, and its newest entry
(160 KB) parsed as markdown on both sides, for a card 12rem tall. The
card is rendered on the server now, from the top of the newest entry cut
on a bullet (about 6 KB). The card has no expand control; View all, the
link beside its heading, opens /changelog as before.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 277 insertions(+), 140 deletions(-)
diff --git a/editor/app/components/dashboard/DashboardCockpit.tsx b/editor/app/components/dashboard/DashboardCockpit.tsx
@@ -1,10 +1,12 @@
"use client";
+import { Suspense, use, type ReactNode } from "react";
import type { ActiveJobsPayload } from "yt-dlp-transcript-common/views/activeJobs";
import type { WorkersPayload } from "yt-dlp-transcript-common/views/workers";
import type { WidgetActionablePayload } from "yt-dlp-transcript-common/views/widgetActionable";
import type { WidgetSyncPayload } from "yt-dlp-transcript-common/views/widgetSync";
import { usePolledPayload, useNow } from "../../lib/usePolledPayload";
+import { SkeletonPanel, SkeletonRows, StreamFilled } from "../StreamSkeleton";
import { PipelineBand } from "./PipelineBand";
import { NeedsWorkPanel } from "./NeedsWorkPanel";
import { QuickAddPanel } from "./QuickAddPanel";
@@ -29,103 +31,193 @@ import { PrioritizeButton } from "../actions/PrioritizeButton";
const FAST_MS = 1000;
const SLOW_MS = 15000;
-export type DashboardCockpitInitial = {
- jobs: ActiveJobsPayload;
- workers: WorkersPayload;
+// WHAT THE CORPUS READ ANSWERS (app/page.tsx `loadCorpus`): the seeds that come
+// off every channel's config and report. One promise, read by the two sections
+// that draw it.
+export type DashboardCorpus = {
actionable: WidgetActionablePayload;
sync: WidgetSyncPayload;
// Built server-side in app/page.tsx and passed straight through — never into
// client state — so a global AutoRefresh re-seeds them live.
channels: ChannelRowView[];
- changelogSource: string | null;
// Set while the corpus has no channel (app/page.tsx): the first-run checklist.
- firstRun?: FirstRunState | null;
+ firstRun: FirstRunState | null;
// The cookie refresh alerts (lib/cookieAlerts.ts), polled SLOW after this.
- cookieAlerts?: ServiceCookieAlertsPayload;
+ cookieAlerts: ServiceCookieAlertsPayload;
// The drive banner (storage/lib/driveHealth.ts), polled SLOW after this.
- driveHealth?: DriveHealthPayload;
+ driveHealth: DriveHealthPayload;
+};
+
+type CockpitProps = {
+ workers: WorkersPayload;
+ // The "Recent changes" card's content, rendered by the server page.
+ changelog: ReactNode;
+ // The two slow reads, STARTED by the page and not awaited there. Each
+ // section below reads the one it needs with `use()` inside its own Suspense
+ // boundary, so the page's shell is sent before either is done.
+ jobs: Promise<ActiveJobsPayload>;
+ corpus: Promise<DashboardCorpus>;
+ // What the skeletons are sized by: counts known without the slow reads.
+ pending: { channels: number; jobs: number };
};
const EMPTY_COOKIE_ALERTS: ServiceCookieAlertsPayload = { alerts: [], pending: [] };
const NO_DRIVE_TROUBLE: DriveHealthPayload = { drives: [] };
-// The mission-control cockpit. A server component (app/page.tsx) SSRs the
-// initial payloads for a flicker-free first paint; this client shell then polls
-// the same /api endpoints the widget uses so the whole surface updates in place.
-export function DashboardCockpit({
- initial,
-}: {
- initial: DashboardCockpitInitial;
-}) {
+// The mission-control cockpit. A server component (app/page.tsx) starts the
+// reads; the shell (the heading, "Add a channel", recent changes) is sent at
+// once and two sections stream in behind it — the live half (pipeline band and
+// "Needs work") and the channels table — each seeded for a flicker-free first
+// paint. The live half then polls the same /api endpoints the widget uses, so
+// the whole surface updates in place.
+//
+// A REFRESH NEVER BRINGS A SKELETON BACK. router.refresh() (the global
+// AutoRefresh, any action) is a transition: the new promises suspend, and
+// React keeps the section that is already on screen until they resolve.
+export function DashboardCockpit(props: CockpitProps) {
+ return (
+ <div className="flex flex-col gap-6">
+ <h1 className="sr-only">Dashboard</h1>
+ <Suspense
+ fallback={
+ <>
+ <SkeletonPanel
+ name="dashboard-pipeline"
+ height={
+ PIPELINE_IDLE_PX +
+ (props.pending.jobs > 0
+ ? PIPELINE_JOBS_CHROME_PX + props.pending.jobs * PIPELINE_JOB_ROW_PX
+ : 0)
+ }
+ />
+ <div className="grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">
+ <SkeletonPanel name="dashboard-needs-work" height={NEEDS_WORK_EMPTY_PX} />
+ <QuickAddPanel changelog={props.changelog} />
+ </div>
+ </>
+ }
+ >
+ <CockpitLive {...props} />
+ </Suspense>
+ <Suspense
+ fallback={
+ props.pending.channels > 0 ? (
+ <section className="flex flex-col gap-3">
+ <h2 className="font-mono text-xs uppercase tracking-[0.14em] text-muted-foreground">
+ Channels
+ </h2>
+ <SkeletonRows
+ name="dashboard-channels"
+ rows={props.pending.channels}
+ rowHeight={CHANNEL_ROW_PX}
+ head={CHANNEL_HEAD_PX}
+ />
+ </section>
+ ) : null
+ }
+ >
+ <CockpitChannels corpus={props.corpus} />
+ </Suspense>
+ </div>
+ );
+}
+
+// THE SKELETONS' SIZES, in px, measured at the desktop width: the idle pipeline
+// band; what a live job list adds to it (its strip and header) and one job's
+// row; the "Needs work" card with nothing in it; the channels table's header
+// and row. e2e/streaming.spec.ts holds each skeleton's box to the box of what
+// replaces it, so a restyle that moves one of these fails there. What is known
+// before the reads is a COUNT, so a section whose height depends on more than
+// that (a job row with several tasks, a "Needs work" list) is held to its
+// usual size, not its exact one.
+const PIPELINE_IDLE_PX = 333;
+const PIPELINE_JOBS_CHROME_PX = 182;
+const PIPELINE_JOB_ROW_PX = 62;
+const NEEDS_WORK_EMPTY_PX = 74;
+const CHANNEL_HEAD_PX = 38;
+const CHANNEL_ROW_PX = 43;
+
+// The live half: the alerts, the pipeline band and "Needs work".
+function CockpitLive({ workers: workersSeed, changelog, jobs: jobsPromise, corpus }: CockpitProps) {
+ const seed = use(corpus);
+ const jobsSeed = use(jobsPromise);
const now = useNow();
const { data: jobs } = usePolledPayload<ActiveJobsPayload>(
"/api/view/activeJobs",
true,
FAST_MS,
- initial.jobs,
+ jobsSeed,
);
const { data: workers, refetch: refetchWorkers } =
usePolledPayload<WorkersPayload>(
"/api/view/workers",
true,
FAST_MS,
- initial.workers,
+ workersSeed,
);
const { data: actionable } = usePolledPayload<WidgetActionablePayload>(
"/api/view/widgetActionable",
true,
SLOW_MS,
- initial.actionable,
+ seed.actionable,
);
const { data: sync, refetch: refetchSync } = usePolledPayload<WidgetSyncPayload>(
"/api/view/widgetSync",
true,
SLOW_MS,
- initial.sync,
+ seed.sync,
);
const { data: cookieAlerts, refetch: refetchCookieAlerts } =
usePolledPayload<ServiceCookieAlertsPayload>(
"/api/view/cookieAlerts",
true,
SLOW_MS,
- initial.cookieAlerts ?? EMPTY_COOKIE_ALERTS,
+ seed.cookieAlerts ?? EMPTY_COOKIE_ALERTS,
);
const { data: driveHealth } = usePolledPayload<DriveHealthPayload>(
"/api/view/driveHealth",
true,
SLOW_MS,
- initial.driveHealth ?? NO_DRIVE_TROUBLE,
+ seed.driveHealth ?? NO_DRIVE_TROUBLE,
);
return (
- <div className="flex flex-col gap-6">
- <h1 className="sr-only">Dashboard</h1>
+ <>
<DriveHealthBanner data={driveHealth ?? NO_DRIVE_TROUBLE} />
<CookieAlertsPanel
data={cookieAlerts ?? EMPTY_COOKIE_ALERTS}
onChange={() => void refetchCookieAlerts()}
/>
- {initial.firstRun && <FirstRunPanel state={initial.firstRun} />}
- <PipelineBand
- jobs={jobs}
- workers={workers}
- sync={sync}
- actionable={actionable}
- now={now}
- onWorkersChange={refetchWorkers}
- onSynced={refetchSync}
- />
+ {seed.firstRun && <FirstRunPanel state={seed.firstRun} />}
+ <StreamFilled name="dashboard-pipeline">
+ <PipelineBand
+ jobs={jobs}
+ workers={workers}
+ sync={sync}
+ actionable={actionable}
+ now={now}
+ onWorkersChange={refetchWorkers}
+ onSynced={refetchSync}
+ />
+ </StreamFilled>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">
- <NeedsWorkPanel data={actionable} />
- <QuickAddPanel changelogSource={initial.changelogSource} />
+ <StreamFilled name="dashboard-needs-work">
+ <NeedsWorkPanel data={actionable} />
+ </StreamFilled>
+ <QuickAddPanel changelog={changelog} />
</div>
- <DashboardChannels channels={initial.channels} now={now} />
- </div>
+ </>
);
}
+function CockpitChannels({ corpus }: { corpus: Promise<DashboardCorpus> }) {
+ const { channels } = use(corpus);
+ const now = useNow();
+ return <DashboardChannels channels={channels} now={now} />;
+}
+
// The dashboard's channels table: the shared channel table with six columns,
// a relative "last sync" that ticks live, and per-row inline actions (Sync,
// Download missing, and a one-click "Top of queue" that prioritizes the channel
@@ -165,15 +257,17 @@ function DashboardChannels({
<h2 className="font-mono text-xs uppercase tracking-[0.14em] text-muted-foreground">
Channels
</h2>
- <ChannelsTable
- rows={channels}
- columns={DASHBOARD_COLUMNS}
- rowLabelPrefix="channel"
- rowExtras={rowExtras}
- sort={false}
- selection={false}
- now={now}
- />
+ <StreamFilled name="dashboard-channels">
+ <ChannelsTable
+ rows={channels}
+ columns={DASHBOARD_COLUMNS}
+ rowLabelPrefix="channel"
+ rowExtras={rowExtras}
+ sort={false}
+ selection={false}
+ now={now}
+ />
+ </StreamFilled>
</section>
);
}
diff --git a/editor/app/components/dashboard/QuickAddPanel.tsx b/editor/app/components/dashboard/QuickAddPanel.tsx
@@ -1,15 +1,16 @@
"use client";
+import type { ReactNode } from "react";
import Link from "next/link";
-import { Changelog } from "yt-dlp-transcript-common/components/Changelog";
// The quiet right-hand column: a prominent entry into the URL-first onboarding
// flow, and the recent-changes card beneath it (reusing the shared Changelog).
-export function QuickAddPanel({
- changelogSource,
-}: {
- changelogSource: string | null;
-}) {
+//
+// `changelog` is the card's content, already rendered by the server page (the
+// top of the newest entry, app/page.tsx): this component ships no markdown and
+// parses none. The card is clipped at 12rem and has no expand control — the
+// whole changelog is "View all", one link away.
+export function QuickAddPanel({ changelog }: { changelog: ReactNode }) {
return (
<section
aria-label="Quick add and changes"
@@ -29,7 +30,7 @@ export function QuickAddPanel({
</p>
</Link>
- {changelogSource && (
+ {changelog && (
// A plain <div>, not a Link: the Changelog renders its own anchors and
// CopyLink buttons, and wrapping interactive content in an outer <a> is
// invalid nesting that the browser reparents — an SSR hydration
@@ -49,7 +50,7 @@ export function QuickAddPanel({
</Link>
</div>
<div className="relative max-h-48 overflow-hidden">
- <Changelog source={changelogSource} limit={1} />
+ {changelog}
<div
aria-hidden="true"
className="pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-gradient-to-t from-card to-transparent"
diff --git a/editor/app/page.tsx b/editor/app/page.tsx
@@ -1,5 +1,6 @@
import { displayPath } from "yt-dlp-transcript-common/lib/privacy/privacy-server";
import { existsSync, readFileSync } from "node:fs";
+import { cache } from "react";
import type { Metadata } from "next";
import { getPaths } from "yt-dlp-transcript-common/lib/paths";
import { inspectChannelMedia } from "yt-dlp-transcript-common/lib/channelMedia";
@@ -19,7 +20,15 @@ import { buildActiveJobsPayload } from "./jobs/active/buildActiveJobs";
import { buildWorkersPayload } from "./workers/buildWorkers";
import { buildWidgetSyncPayload } from "yt-dlp-transcript-common/views/widgetSync";
import { widgetSyncInputs } from "./widget/lib/syncInputs";
-import { DashboardCockpit } from "./components/dashboard/DashboardCockpit";
+import {
+ DashboardCockpit,
+ type DashboardCorpus,
+} from "./components/dashboard/DashboardCockpit";
+import { Changelog } from "yt-dlp-transcript-common/components/Changelog";
+import { changelogPreview } from "yt-dlp-transcript-common/lib/changelog";
+import { listChannelSlugs } from "yt-dlp-transcript-common/controller/channels";
+import { getRegistry } from "yt-dlp-transcript-common/jobs/registry";
+import { e2eStreamDelay } from "./lib/streamDelay";
import { loadCookieAlerts } from "./lib/cookieAlerts";
import { buildDriveHealthPayload } from "./storage/lib/driveHealth";
import {
@@ -59,107 +68,140 @@ function firstRunState(paths: Paths): FirstRunState {
return { workers, siteCount: listSiteIds(paths).length };
}
-function loadChangelog(): string | null {
+// THE "RECENT CHANGES" CARD, RENDERED HERE. The card is 12rem tall and clipped
+// (QuickAddPanel), and "View all" beside it opens /changelog. The whole file
+// used to be handed to the client component as a string — 900 KB, doubled in
+// the document — and the newest entry (160 KB) parsed as markdown on the server
+// and again in the browser, to show its first few lines. What is rendered now
+// is the top of the newest entry, cut on a bullet (changelogPreview), and it
+// is rendered once, on the server: the client gets the elements, not markdown.
+function loadChangelogCard(): React.ReactNode {
try {
- return readFileSync(getPaths().editorChangelogFile, "utf8");
+ const source = readFileSync(getPaths().editorChangelogFile, "utf8");
+ return <Changelog source={changelogPreview(source)} limit={1} />;
} catch {
return null;
}
}
+// EVERYTHING THE DASHBOARD READS OFF THE CORPUS — every channel's config and
+// report, where each one's media is, the sync state, the cookie alerts and the
+// drives. One read for the two sections that draw it (the cockpit's live half
+// and the channels table), started by the page and NOT awaited there: the
+// page's shell is sent first and each section streams in behind its own
+// boundary (DashboardCockpit).
+const loadCorpus = cache(
+ async (paths: Paths, siteParam: string | undefined): Promise<DashboardCorpus> => {
+ await e2eStreamDelay();
+ // The active site: a `?site=` link's for this request, else the cookie's.
+ const active = await readActiveSite(siteParam, listSiteIds(paths));
+ const summary = await getActionableSummary(paths);
+
+ // Scope the channel-derived data to the active site's membership. Under
+ // "all sites" the full pool is shown. Job/worker state stays global (pool
+ // state).
+ const inScope = (() => {
+ if (active.isAll || !active.siteId) return () => true;
+ const slugs = siteChannelSlugs(getSite(active.siteId, paths));
+ return (r: ActionableRow) => slugs.has(r.channel.slug);
+ })();
+ const rows = summary.rows.filter(inScope);
+
+ // WHERE EACH CHANNEL'S MEDIA IS — two stats and a small JSON read per row,
+ // with the config already in hand. Not a corpus walk. A row whose drive is
+ // not mounted reports every other number as zero, which is exactly why the
+ // dashboard has to be able to say so rather than drawing a confident zero.
+ const mediaBySlug = new Map(
+ await Promise.all(
+ rows.map(
+ async (r) =>
+ [
+ r.channel.slug,
+ await inspectChannelMedia(paths, r.channel.slug, r.channel.config),
+ ] as const,
+ ),
+ ),
+ );
+ // Read once for the whole table, not once per row.
+ const locations = getSettings().storage.locations;
+ // The shared channel row (common/views/channelRow.ts), drawn by the shared
+ // table with the dashboard's six columns. No pipeline bands and a neutral
+ // priority: this table draws neither.
+ const channels: ChannelRowView[] = rows.map((r) => {
+ const media = mediaBySlug.get(r.channel.slug) ?? null;
+ return buildChannelRowView({
+ slug: r.channel.slug,
+ config: r.channel.config,
+ // From the snapshot rather than a corpus walk, so the Videos figure
+ // lags a sync by the snapshot scheduler's debounce.
+ snapshot: r.snapshot,
+ playlistCount: null,
+ bands: [],
+ priority: neutralChannelPriority(),
+ media,
+ volume: channelVolumeOf(r.channel.config, locations),
+ // The named location, matched against the configured roots from the
+ // media TARGET, as this table always has. A pure prefix match, never a
+ // probe.
+ mediaLocationLabel: media
+ ? locationLabelOfDataDir(media.target, locations)
+ : undefined,
+ // settings.privacy: the badge's "relocated to <path>" as displayed.
+ show: displayPath,
+ });
+ });
+
+ // "Needs work" payload, same shape (and the same two functions) the
+ // /api/view/widgetActionable handler the cockpit polls serves, scoped to
+ // the active site for the SSR seed.
+ const actionable = buildWidgetActionablePayload(widgetActionableRows(rows));
+
+ const [sync, cookieAlerts, driveHealth] = await Promise.all([
+ widgetSyncInputs().then(buildWidgetSyncPayload),
+ loadCookieAlerts(paths),
+ buildDriveHealthPayload(),
+ ]);
+ return {
+ actionable,
+ sync,
+ channels,
+ firstRun: summary.rows.length === 0 ? firstRunState(paths) : null,
+ cookieAlerts,
+ driveHealth,
+ };
+ },
+);
+
+// The live job list: its own read, so a job whose progress has to be counted
+// off the disk (a walk of that channel's data/) holds back only the cockpit's
+// live half, never the page.
+async function loadJobs() {
+ await e2eStreamDelay();
+ return buildActiveJobsPayload();
+}
+
export default async function Dashboard({
searchParams,
}: {
searchParams: Promise<{ site?: string }>;
}) {
const paths = getPaths();
- // The active site: a `?site=` link's for this request, else the cookie's.
const { site } = await searchParams;
- const active = await readActiveSite(site, listSiteIds(paths));
- const summary = await getActionableSummary(paths);
-
- // Scope the channel-derived data to the active site's membership. Under "all
- // sites" the full pool is shown. Job/worker state stays global (pool state).
- const inScope = (() => {
- if (active.isAll || !active.siteId) return () => true;
- const slugs = siteChannelSlugs(getSite(active.siteId, paths));
- return (r: ActionableRow) => slugs.has(r.channel.slug);
- })();
- const rows = summary.rows.filter(inScope);
-
- // Enriched channels table rows (pass-through, not client state, so a global
- // AutoRefresh re-seeds them live).
- // WHERE EACH CHANNEL'S MEDIA IS — two stats and a small JSON read per row,
- // with the config already in hand. Not a corpus walk. A row whose drive is
- // not mounted reports every other number as zero, which is exactly why the
- // dashboard has to be able to say so rather than drawing a confident zero.
- const mediaBySlug = new Map(
- await Promise.all(
- rows.map(
- async (r) =>
- [
- r.channel.slug,
- await inspectChannelMedia(paths, r.channel.slug, r.channel.config),
- ] as const,
- ),
- ),
- );
- // Read once for the whole table, not once per row.
- const locations = getSettings().storage.locations;
- // The shared channel row (common/views/channelRow.ts), drawn by the shared
- // table with the dashboard's six columns. No pipeline bands and a neutral
- // priority: this table draws neither.
- const channels: ChannelRowView[] = rows.map((r) => {
- const media = mediaBySlug.get(r.channel.slug) ?? null;
- return buildChannelRowView({
- slug: r.channel.slug,
- config: r.channel.config,
- // From the snapshot rather than a corpus walk, so the Videos figure lags
- // a sync by the snapshot scheduler's debounce.
- snapshot: r.snapshot,
- playlistCount: null,
- bands: [],
- priority: neutralChannelPriority(),
- media,
- volume: channelVolumeOf(r.channel.config, locations),
- // The named location, matched against the configured roots from the
- // media TARGET, as this table always has. A pure prefix match, never a
- // probe.
- mediaLocationLabel: media
- ? locationLabelOfDataDir(media.target, locations)
- : undefined,
- // settings.privacy: the badge's "relocated to <path>" as displayed.
- show: displayPath,
- });
- });
-
- // "Needs work" payload, same shape (and the same two functions) the
- // /api/view/widgetActionable handler the cockpit polls serves, scoped to the
- // active site for the SSR seed.
- const actionable = buildWidgetActionablePayload(widgetActionableRows(rows));
-
- const [jobs, sync, cookieAlerts, driveHealth] = await Promise.all([
- buildActiveJobsPayload(),
- widgetSyncInputs().then(buildWidgetSyncPayload),
- loadCookieAlerts(paths),
- buildDriveHealthPayload(),
- ]);
- const workers = buildWorkersPayload();
- const changelogSource = loadChangelog();
+ // WHAT THE SKELETONS ARE SIZED BY, known without either slow read: how many
+ // channels there are (one readdir) and how many jobs are live (memory).
+ // Under a site scope the table is shorter than this; the count is the pool's.
+ const slugs = await listChannelSlugs(paths);
+ const liveJobs = getRegistry()
+ .list()
+ .filter((j) => j.status === "running" || j.status === "queued").length;
return (
<DashboardCockpit
- initial={{
- jobs,
- workers,
- actionable,
- sync,
- channels,
- changelogSource,
- firstRun: summary.rows.length === 0 ? firstRunState(paths) : null,
- cookieAlerts,
- driveHealth,
- }}
+ workers={buildWorkersPayload()}
+ changelog={loadChangelogCard()}
+ jobs={loadJobs()}
+ corpus={loadCorpus(paths, site)}
+ pending={{ channels: slugs.length, jobs: liveJobs }}
/>
);
}