🔀 Integrate current dev into review and source safety release

# Conflicts:
#	src/components/CaptureAnnotationWorkbench.tsx
#	src/pages/AnnotationOperations.tsx
This commit is contained in:
Codex 2026-11-03 07:08:29 -08:00
commit e2e35cf6a2
11 changed files with 300 additions and 19 deletions

View File

@ -0,0 +1,58 @@
# Frontend first-screen loading
This change moves non-critical modules out of the eager application entry and
onto the chunks that actually render them. No page markup, interaction or
styling rule changed; only when a resource is fetched.
## What left the first screen
| Resource | Before | After |
| --------------------------------------------------------------------- | ----------------------------------------------------------------- | -------------------------------------------------------- |
| `lucide-react` (`icons-vendor`) | Statically reachable from the entry through `Layout`, `Sidebar`, `PluginRouteGuard` and `UserBootstrapPanel`, so the entry preloaded the union of every icon used by all lazy pages. | The eager shell uses `src/components/shell-icons.tsx`; the icon vendor chunk is only requested when a route that imports lucide renders. |
| `Sidebar` (navigation JSX, supplier/users helpers) | Bundled in the entry and parsed on every first paint. | Dynamic `import("./Sidebar")`, warmed only when `droboticflow.currentUserId` already exists. |
| `src/styles/capture-workspace.css` | Imported by the global `src/index.css`, so every page downloaded the annotation workspace layout rules. | Imported by `CaptureAnnotationWorkbench`, emitted with the annotation route CSS. |
| `WorkforceStatisticsPanel` | Bundled in the lazy Dashboard chunk even though it only renders in the collapsed legacy overview. | Lazy import inside a local `Suspense` boundary. |
The eager shell now contains only React, React DOM, React Router, the context
providers, the API client, `Layout`, the plugin guard and the login panel.
## Measuring FCP/LCP
Build once per revision and serve `dist/` (the Go SPA handler or any static
server that also answers `/api/*` for the auth check):
```bash
npm run build:web
```
Capture both metrics in a Playwright page with a fresh browser context:
```js
await page.addInitScript(() => {
window.__vitals = {};
new PerformanceObserver((list) => {
for (const entry of list.getEntries()) window.__vitals.fcp = entry.startTime;
}).observe({ type: "paint", buffered: true });
new PerformanceObserver((list) => {
const entries = list.getEntries();
window.__vitals.lcp = entries[entries.length - 1].startTime;
}).observe({ type: "largest-contentful-paint", buffered: true });
});
await page.goto(origin, { waitUntil: "networkidle" });
const vitals = await page.evaluate(() => window.__vitals);
```
Run the same script against the base commit and this branch with the same
network/CPU throttling and the same auth fixture. The first screen for an
unauthenticated session must not request `icons-vendor`, the `Sidebar` chunk or
the annotation workspace stylesheet. For a returning session the `Sidebar`
chunk is warmed as soon as the shell paints, concurrently with `/api/auth/me`,
instead of after the route starts rendering.
## Verification commands
```bash
npm run lint:web
npm run test:frontend:gate
npm run build:web
```

View File

@ -1,4 +1,8 @@
import type { AnnotationTimelineFailure } from "../lib/annotation-source-validation";
// Workbench-only layout rules. Loading them with this component (instead of
// the global entry stylesheet) keeps the annotation workspace CSS off the
// application's first screen.
import "../styles/capture-workspace.css";
import {
createSliceEditSession,
freezeSliceEditSession,

View File

@ -1,11 +1,10 @@
import React, { useEffect, useRef, useState } from "react";
import React, { Suspense, lazy, useEffect, useRef, useState } from "react";
import { useLocation } from "react-router-dom";
import {
AnnotationWorkspaceLayoutContext,
useAnnotationLayoutPreference,
} from "../context/AnnotationWorkspaceLayoutContext";
import { Loader2, Moon, Sun } from "lucide-react";
import { Sidebar } from "./Sidebar";
import { Loader2, Moon, Sun } from "./shell-icons";
import { UserBootstrapPanel } from "./UserBootstrapPanel";
import { useUser } from "../context/UserContext";
import { getActionErrorMessage } from "../lib/action-errors.js";
@ -17,6 +16,26 @@ interface LayoutProps {
children: React.ReactNode;
}
// The sidebar is only mounted after the current user resolves, but it is not
// needed to paint the shell. Keeping it in its own chunk removes its icon set
// and API helpers from the entry bundle; a returning user starts the request
// as soon as the shell paints so the navigation is ready when auth completes.
const Sidebar = lazy(() => import("./Sidebar").then((module) => ({ default: module.Sidebar })));
const CURRENT_USER_STORAGE_KEY = "droboticflow.currentUserId";
function SidebarFallback({ collapsed }: { collapsed: boolean }) {
return (
<aside
aria-hidden="true"
className={[
"relative flex h-screen shrink-0 flex-col border-r border-[color:var(--app-border)] bg-[color:var(--app-sidebar)]",
collapsed ? "w-20" : "w-64",
].join(" ")}
/>
);
}
type HealthState = {
status: "loading" | "online" | "offline";
service?: string;
@ -70,6 +89,18 @@ export function Layout({ children }: LayoutProps) {
return () => mobileViewport.removeEventListener("change", collapseForMobile);
}, []);
useEffect(() => {
// Only warm modules for sessions that were already authenticated; a first
// visit to the login screen must not download app-only chunks.
if (!window.localStorage.getItem(CURRENT_USER_STORAGE_KEY)) {
return;
}
const timer = window.setTimeout(() => {
void import("./Sidebar");
}, 0);
return () => window.clearTimeout(timer);
}, []);
useEffect(() => {
let cancelled = false;
@ -192,7 +223,9 @@ export function Layout({ children }: LayoutProps) {
className="flex h-screen bg-[color:var(--app-canvas)] font-sans text-[color:var(--app-text)]"
>
{currentUser && !isSuperAdmin && !focusedWorkPage ? (
<Sidebar isCollapsed={isCollapsed} onToggle={() => setIsCollapsed(!isCollapsed)} />
<Suspense fallback={<SidebarFallback collapsed={isCollapsed} />}>
<Sidebar isCollapsed={isCollapsed} onToggle={() => setIsCollapsed(!isCollapsed)} />
</Suspense>
) : null}
<main className="relative flex min-w-0 flex-1 flex-col overflow-hidden">
<header

View File

@ -1,5 +1,5 @@
import React from "react";
import { Blocks, Loader2 } from "lucide-react";
import { Blocks, Loader2 } from "./shell-icons";
import { Link } from "react-router-dom";
import { usePlugins } from "../context/PluginContext";
import { useUser } from "../context/UserContext";

View File

@ -1,6 +1,6 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useMemo, useState } from "react";
import { AlertCircle, Loader2, Lock, LogIn, Phone, Shield, User } from "lucide-react";
import { AlertCircle, Loader2, Lock, LogIn, Phone, Shield, User } from "./shell-icons";
import { useUser } from "../context/UserContext";
import { getActionErrorMessage } from "../lib/action-errors.js";

View File

@ -0,0 +1,129 @@
import type { ReactNode } from "react";
/**
* Icons for the always-mounted application shell (Layout, PluginRouteGuard and
* the login panel). They mirror the lucide-react icon nodes the shell used to
* import, but living here keeps the shell out of the shared `icons-vendor`
* chunk: that chunk contains every icon the whole app imports, so a single
* lucide import from the eager entry pulled all of them into the first screen.
*
* Keep the generated SVG attributes identical to lucide's (24px viewBox,
* currentColor stroke, 2px stroke width) so sizing and colour utilities keep
* working unchanged.
*/
type ShellIconProps = { className?: string };
function ShellIcon({ name, className, children }: ShellIconProps & { name: string; children: ReactNode }) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className={["lucide", `lucide-${name}`, className].filter(Boolean).join(" ")}
aria-hidden="true"
>
{children}
</svg>
);
}
export function Loader2({ className }: ShellIconProps) {
return (
<ShellIcon name="loader-circle" className={className}>
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
</ShellIcon>
);
}
export function Moon({ className }: ShellIconProps) {
return (
<ShellIcon name="moon" className={className}>
<path d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401" />
</ShellIcon>
);
}
export function Sun({ className }: ShellIconProps) {
return (
<ShellIcon name="sun" className={className}>
<circle cx="12" cy="12" r="4" />
<path d="M12 2v2" />
<path d="M12 20v2" />
<path d="m4.93 4.93 1.41 1.41" />
<path d="m17.66 17.66 1.41 1.41" />
<path d="M2 12h2" />
<path d="M20 12h2" />
<path d="m6.34 17.66-1.41 1.41" />
<path d="m19.07 4.93-1.41 1.41" />
</ShellIcon>
);
}
export function Blocks({ className }: ShellIconProps) {
return (
<ShellIcon name="blocks" className={className}>
<path d="M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2" />
<rect x="14" y="2" width="8" height="8" rx="1" />
</ShellIcon>
);
}
export function AlertCircle({ className }: ShellIconProps) {
return (
<ShellIcon name="circle-alert" className={className}>
<circle cx="12" cy="12" r="10" />
<path d="M12 8v4" />
<path d="M12 16h.01" />
</ShellIcon>
);
}
export function Lock({ className }: ShellIconProps) {
return (
<ShellIcon name="lock" className={className}>
<rect width="18" height="11" x="3" y="11" rx="2" ry="2" />
<path d="M7 11V7a5 5 0 0 1 10 0v4" />
</ShellIcon>
);
}
export function LogIn({ className }: ShellIconProps) {
return (
<ShellIcon name="log-in" className={className}>
<path d="m10 17 5-5-5-5" />
<path d="M15 12H3" />
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4" />
</ShellIcon>
);
}
export function Phone({ className }: ShellIconProps) {
return (
<ShellIcon name="phone" className={className}>
<path d="M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384" />
</ShellIcon>
);
}
export function Shield({ className }: ShellIconProps) {
return (
<ShellIcon name="shield" className={className}>
<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z" />
</ShellIcon>
);
}
export function User({ className }: ShellIconProps) {
return (
<ShellIcon name="user" className={className}>
<path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" />
<circle cx="12" cy="7" r="4" />
</ShellIcon>
);
}

View File

@ -1,5 +1,4 @@
@import "tailwindcss";
@import "./styles/capture-workspace.css";
/* Keep the reviewer controls usable inside a narrow workbench, not merely a
wide viewport. Never hide overflowing buttons behind the page scroller. */

View File

@ -1,5 +1,8 @@
import { annotationTimelineFailure } from "../lib/annotation-source-validation.js";
import type { AnnotationTimelineFailure } from "../lib/annotation-source-validation";
// Keep the workbench rules ahead of the review framing rules, matching the
// order they had when both were pulled in by the global entry stylesheet.
import "../styles/capture-workspace.css";
import "../styles/review-workspace.css";
import { AcceptanceMisreports } from "../components/AcceptanceMisreports";
import { useReviewTrace, ReviewTracePanel, ReviewListTrace } from "../components/ReviewTrace";

View File

@ -1,6 +1,6 @@
import { ProductionQualityDashboard } from "../components/ProductionQualityDashboard";
import { userErrorMessage } from "../lib/user-error-message.js";
import { WorkforceStatisticsPanel, type WorkforceFilters } from "../components/WorkforceStatisticsPanel";
import type { WorkforceFilters } from "../components/WorkforceStatisticsPanel";
import { defaultProductionFilters, type ProductionFilters } from "../lib/production-filters";
import React, { Suspense, lazy, useCallback, useEffect, useState } from "react";
import {
@ -52,25 +52,38 @@ const ProductionStatistics = lazy(() =>
import("../components/ProductionStatistics").then((module) => ({ default: module.ProductionStatistics })),
);
// The workforce report lives in the collapsed legacy overview (and the
// non-admin summary). Keep its table/modal code out of the dashboard chunk
// that must load for the first screen.
const WorkforceStatisticsPanel = lazy(() =>
import("../components/WorkforceStatisticsPanel").then((module) => ({ default: module.WorkforceStatisticsPanel })),
);
function ProductionStatisticsFallback() {
return <p className="text-sm text-slate-500 dark:text-gray-400">正在加载生产总览...</p>;
}
function WorkforceStatisticsFallback() {
return <p className="text-sm text-slate-500 dark:text-gray-400">正在加载工作量统计...</p>;
}
function WorkforceSummaryPanel({ summary, filters }: { summary: DashboardSummary | null; filters: WorkforceFilters }) {
const { currentUser } = useUser();
const reviewer = currentUser?.role === "quality_reviewer" || currentUser?.role === "acceptance_reviewer";
return (
<WorkforceStatisticsPanel
items={summary?.workforce?.items || []}
totals={summary?.workforce?.totals}
from={summary?.workforce?.from || filters.from}
to={summary?.workforce?.to || filters.to}
filters={filters}
self={summary?.audienceScope === "self"}
vendor={summary?.audienceScope === "vendor"}
collapsedByDefault={!reviewer}
deferLoad
/>
<Suspense fallback={<WorkforceStatisticsFallback />}>
<WorkforceStatisticsPanel
items={summary?.workforce?.items || []}
totals={summary?.workforce?.totals}
from={summary?.workforce?.from || filters.from}
to={summary?.workforce?.to || filters.to}
filters={filters}
self={summary?.audienceScope === "self"}
vendor={summary?.audienceScope === "vendor"}
collapsedByDefault={!reviewer}
deferLoad
/>
</Suspense>
);
}

View File

@ -0,0 +1,39 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
const source = (path) => readFile(new URL(`../../${path}`, import.meta.url), "utf8");
test("the eager application shell does not import the shared lucide vendor chunk", async () => {
const files = await Promise.all([
source("src/components/Layout.tsx"),
source("src/components/PluginRouteGuard.tsx"),
source("src/components/UserBootstrapPanel.tsx"),
]);
for (const file of files) {
assert.doesNotMatch(file, /from "lucide-react"/);
assert.match(file, /from "\.\/shell-icons"/);
}
});
test("the sidebar is code-split out of the shell and only warmed for returning sessions", async () => {
const layout = await source("src/components/Layout.tsx");
assert.match(layout, /const Sidebar = lazy\(\(\) => import\("\.\/Sidebar"\)/);
assert.match(layout, /currentUserId/);
assert.match(layout, /import\("\.\/Sidebar"\)/);
});
test("annotation workspace CSS loads with the annotation route, not the entry stylesheet", async () => {
const [indexCss, workbench] = await Promise.all([
source("src/index.css"),
source("src/components/CaptureAnnotationWorkbench.tsx"),
]);
assert.doesNotMatch(indexCss, /styles\/capture-workspace\.css/);
assert.match(workbench, /styles\/capture-workspace\.css/);
});
test("below-the-fold dashboard panels are lazily imported", async () => {
const dashboard = await source("src/pages/Dashboard.tsx");
assert.match(dashboard, /const WorkforceStatisticsPanel = lazy\(/);
assert.match(dashboard, /const ProductionStatistics = lazy\(/);
});

View File

@ -153,6 +153,9 @@ export function reviewSeekHarness(overrides = {}) {
if (name === "react") return hooks;
if (name === "react/jsx-runtime") return { jsx: element, jsxs: element, Fragment: "fragment" };
if (name === "lucide-react") return new Proxy({}, { get: (_, key) => key });
// CSS side-effect imports carry no runtime state; this seam only exercises
// component logic, and the vm loader cannot execute stylesheets.
if (name.endsWith(".css")) return {};
if (name.endsWith("/movi-player")) return { moviRuntimeMode: () => "native" };
if (name === "./MoviVideo") return { moviElementReady: () => false };
if (name.startsWith("./") && path.basename(file) === "CaptureAnnotationWorkbench.tsx")