Files
Nathan Rajlich 7653e6bfdb Migrate @workflow/web from Next.js to React Router v7 (#1005)
## Summary

- Replace Next.js App Router with React Router v7.13.0 framework mode (Vite-based), eliminating the large `next` dependency from the web, CLI, and workflow metapackages
- Serve the web UI in-process from the CLI via Express instead of spawning `next start` as a child process
- Switch RPC transport from JSON to CBOR to preserve binary data types across the wire
- Replace `nuqs` URL state management with React Router's `useSearchParams`
- Replace Next.js server actions with an RPC resource route (`/api/rpc`) and a thin CBOR-based client

## Motivation

The `next` package is ~300MB installed and was the single largest dependency in the monorepo. It also required spawning a separate child process from the CLI to run the o11y web server, adding complexity around process lifecycle management, port readiness polling, and environment variable forwarding.

With React Router framework mode, the web package builds to a standard Express-compatible server bundle that the CLI can import and serve directly in its own process.

## What changed

**Framework swap (`@workflow/web`):**
- `next.config.ts` / `postcss.config.mjs` → `react-router.config.ts` / `vite.config.ts`
- `src/` directory → `app/` directory (React Router convention)
- `src/app/layout.tsx` + `layout-client.tsx` → `app/root.tsx`
- `src/app/page.tsx` → `app/routes/home.tsx`
- `src/app/run/[runId]/page.tsx` → `app/routes/run-detail.tsx`
- Path alias `@/` → `~/`
- Removed all `'use client'` / `'use server'` directives

**Data transport:**
- Server actions → RPC resource route at `/api/rpc` with CBOR encoding
- CBOR preserves `Uint8Array` and other binary types natively (no base64 overhead)
- Stream reading → dedicated `/api/stream/:streamId` resource route

**URL state:**
- `nuqs` (`useQueryState`) → `useSearchParams` from `react-router`

**Fonts:**
- `next/font/google` → Geist `.woff2` files referenced directly from `node_modules/geist` via `@font-face` in CSS

**CLI integration (`@workflow/cli`):**
- `import('@workflow/web/server').then(m => m.startServer(port))`
- No child process, no readiness polling, no cleanup handlers

**Radix UI compatibility:**
- `onSubmit` preventDefault on `AlertDialogContent` and `SheetContent` to prevent Radix's internal `<form method="dialog">` from triggering React Router route actions
- Catch-all action on root route for any stray POSTs

## Dependencies removed
- `next`, `swr`, `nuqs`, `@tailwindcss/postcss`

## Dependencies added
- `react-router` / `@react-router/dev` / `@react-router/node` / `@react-router/express` (all `7.13.0`)
- `express`, `vite`, `@tailwindcss/vite`, `cbor-x`, `isbot`, `cross-env`
- `geist` (devDep)
2026-02-12 16:30:51 -08:00

73 lines
2.6 KiB
TypeScript

import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
import { Check, Minus } from 'lucide-react';
import * as React from 'react';
import { cn } from '~/lib/utils';
export interface CheckboxProps
extends Omit<
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>,
'checked' | 'onCheckedChange'
> {
/** Whether the checkbox is checked */
checked?: boolean;
/** Whether the checkbox is in indeterminate state (for "select all" with partial selection) */
indeterminate?: boolean;
/** Callback when checked state changes */
onCheckedChange?: (checked: boolean) => void;
}
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
CheckboxProps
>(({ className, checked, indeterminate, onCheckedChange, ...props }, ref) => {
// Generate a unique id for associating label with checkbox
const id = React.useId();
const checkboxId = props.id ?? id;
// Convert our boolean props to Radix's CheckedState
const checkedState: CheckboxPrimitive.CheckedState = indeterminate
? 'indeterminate'
: (checked ?? false);
return (
// Label provides the click grace area and proper a11y association
<label
htmlFor={checkboxId}
className="p-2 -m-2 inline-flex items-center justify-center cursor-pointer"
onClick={(e) => e.stopPropagation()}
onKeyDown={(e) => e.stopPropagation()}
>
<CheckboxPrimitive.Root
ref={ref}
id={checkboxId}
checked={checkedState}
onCheckedChange={(state: CheckboxPrimitive.CheckedState) => {
// Convert Radix's CheckedState back to boolean
// 'indeterminate' becomes false on click (standard behavior)
onCheckedChange?.(state === true);
}}
className={cn(
'peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
'disabled:cursor-not-allowed disabled:opacity-50',
'data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground',
'data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground',
className
)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center text-current">
{indeterminate ? (
<Minus className="h-3.5 w-3.5" />
) : (
<Check className="h-3.5 w-3.5" />
)}
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
</label>
);
});
Checkbox.displayName = 'Checkbox';
export { Checkbox };