Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Viewport API — implementation plan
Spec / source: .ai/specs/2026-10-07-viewport-api.md
Status: approved
Branch: feat/mobile-redesign
Progress
- Task 1: Viewport constants and hint cookie in
@carbon/utils - Task 2:
Viewport.tsxwithViewportProvideranduseViewportin@carbon/react - Task 3: Migrate every
useCompact/useIsMobilecall site - Task 4: ERP root wiring
- Task 5: CSS — delete the gate, split the global phone block
- Task 6: Rewrite
compact:classes tomax-md: - Task 7: Static verification
- Task 8: Browser verification (only with the owner's go-ahead)
Dependencies
Task 2 needs Task 1. Task 3 and Task 4 need Task 2. Task 5 and Task 6 are independent of Tasks 1–4. Task 7 needs Tasks 1–6. Task 8 needs Task 7.
🛑 Never commit. The owner commits.
Task 1: Viewport constants and hint cookie in @carbon/utils
Depends on: none Files:
- Modify:
packages/utils/src/viewport.ts— replace the compact API with the viewport API - Modify:
packages/utils/src/viewport.test.ts— test the new API
Steps:
- Replace the exports of
viewport.tswith:export type Viewport = "phone" | "tablet" | "desktop";export const VIEWPORT_HINT_COOKIE = "viewport";export const PHONE_QUERY = "(width < 48rem)";export const TABLET_QUERY = "(48rem <= width < 64rem)";export function getViewportHint(request: Request): Viewport— the cookie value if it is one of the three names, else"phone"when the user agent matches/Mobi/i, else"desktop".export function viewportHintCookie(viewport: Viewport): string— samecookie.serializeoptions as today.
- Delete
COMPACT_HINT_COOKIE,COMPACT_QUERY,getCompactHint,compactHintCookie. - Rewrite
viewport.test.tsagainst the new API: the three cookie values round-trip, an unknown value falls back to the UA, the iPhone UA gives"phone", the Mac UA gives"desktop", and the cookie hasMax-Age=31536000andPath=/.
Verify:
pnpm --filter @carbon/utils test -- viewport
# Expected: all viewport tests pass
Out of scope: any other file in @carbon/utils.
Task 2: Viewport.tsx in @carbon/react
Depends on: Task 1 Files:
- Create:
packages/react/src/Viewport.tsx(viagit mv packages/react/src/Compact.tsx packages/react/src/Viewport.tsx) - Delete:
packages/react/src/hooks/useIsMobile.ts - Modify:
packages/react/src/hooks/index.ts— removeuseIsMobile - Modify:
packages/react/src/index.tsx— exportViewportProvider,useViewportinstead ofCompactProvider,useCompact - Modify: every
packages/react/src/*.tsxthat imports from./Compact— import from./Viewport
Steps:
- In
Viewport.tsx, keep the SPDX header andHitArea. Change theHitAreaclasses fromcompact:tomax-md:. - Replace the context, provider and hooks with:
- Context value
{ initialViewport: Viewport } | null. ViewportProvider({ initialViewport, children }). On mount, compute the size fromPHONE_QUERYandTABLET_QUERY, writeviewportHintCookie(size), and rewrite it on eachchangeevent of both queries.readViewport(): Viewport:"phone"ifPHONE_QUERYmatches,"tablet"ifTABLET_QUERYmatches, else"desktop".subscribeadds thechangelistener to both media query lists.useViewport():const size = useSyncExternalStore(subscribe, readViewport, () => context?.initialViewport ?? "desktop"); returnuseMemo(() => ({ isPhone: size === "phone", isTablet: size === "tablet", isDesktop: size === "desktop" }), [size]).
- Context value
- Delete
useCompact,useIsMobile,CompactProvider. Update the doc comments: no opt-in remains. - Delete
hooks/useIsMobile.tsand its import and export inhooks/index.ts. - In
index.tsx, import and exportViewportProvideranduseViewportfrom./Viewport. - In each
packages/react/srcfile that importsuseCompactfrom./Compact, importuseViewportfrom./Viewport. Task 3 rewrites the calls.
Verify: Task 3 verifies (the package does not typecheck until call sites move).
Out of scope: CompactSheet.tsx and every other Compact* component name.
Task 3: Migrate every useCompact / useIsMobile call site
Depends on: Task 2
Files: about 71 files that call useCompact, plus packages/react/src/Sidebar.tsx, packages/react/src/FunnelChart.tsx, apps/mes/app/routes/x+/active.tsx, apps/mes/app/routes/x+/recent.tsx, apps/starter/app/components/Breadcrumbs.tsx.
Steps:
- Replace
const isCompact = useCompact();withconst { isPhone } = useViewport();(82 sites). In the same file, rename everyisCompactidentifier toisPhone.CollapsibleSidebar.tsx'swasCompactref stays. - Replace an inline
useCompact()(8 sites:useCompact() ? (anduseCompact() ? Phone :) withuseViewport().isPhone. - Replace
const isMobile = useIsMobile();withconst { isPhone: isMobile } = useViewport();. Keep the local name so the rest of each file stays as it is. - In each file's import from
@carbon/react(or./hooks/./Compactinside the package), swapuseCompact/useIsMobileforuseViewport. Remove duplicates. - If a file shadows
isPhonealready, STOP and report — do not improvise.
Verify:
rg -n "useCompact\b|useIsMobile|CompactProvider|initialCompact" apps packages -g '*.{ts,tsx}'
# Expected: only apps/erp/app/root.tsx (Task 4)
pnpm exec turbo run typecheck --filter=@carbon/utils --filter=@carbon/react --filter=mes --filter=starter --filter=academy
# Expected: all tasks succeed
Out of scope: props or components named Compact*; the compact prop of Table.
Task 4: ERP root wiring
Depends on: Task 2 Files:
- Modify:
apps/erp/app/root.tsx
Steps:
- Import
getViewportHintinstead ofgetCompactHint, andViewportProviderinstead ofCompactProvider. - In the loader, replace
compact: getCompactHint(request)withviewport: getViewportHint(request). - Delete
data-compact-ui=""and its two comment lines from<html>. - Replace
<CompactProvider initialCompact={loaderData?.compact ?? false}>with<ViewportProvider initialViewport={loaderData?.viewport ?? "desktop"}>, and the closing tag.
Verify:
pnpm exec turbo run typecheck --filter=erp
# Expected: succeeds (after Task 3)
Out of scope: the rest of root.tsx.
Task 5: CSS — delete the gate, split the global phone block
Depends on: none Files:
- Modify:
packages/config/tailwind/theme.css - Modify:
apps/erp/app/styles/tailwind.css
Steps:
- Delete
@custom-variant compact { … }and its comment. - In
@custom-variant hover, delete the:where(html:not([data-compact-ui])) &:hover { @slot; }block. Update the comment above it. - Update the
@utility hit-areacomment:compact:hit-area→max-md:hit-area. - In the
@media (width < 48rem)phone block, keep only the two shared rules, with new selectors:html:not(.dark) { --muted-foreground: … !important; }and.truncate { white-space: nowrap; }. Update the block comment. - Append to
apps/erp/app/styles/tailwind.cssa@media (width < 48rem)block withhtml { --topbar-height: calc(52px + env(safe-area-inset-top)); }and[data-sonner-toaster][data-y-position="bottom"] { bottom: calc(var(--content-inset, 0px) + 16px); }, with their comments.
Verify:
rg -n "data-compact-ui|custom-variant compact" packages apps -g '*.{css,ts,tsx}'
# Expected: no output
Out of scope: every other rule in both files.
Task 6: Rewrite compact: classes to max-md:
Depends on: none
Files: about 270 .ts / .tsx files under apps/ and packages/.
Steps:
- Run a Perl rewrite over tracked
.ts/.tsxfiles underappsandpackagesthat replacescompact:withmax-md:only when the char before is a space,",',`or(, and the char after is[a-z[!-]. This leavescompact: trueobject keys alone. - Check
packages/react/src/Card.tsx: the selector[class~='compact:hidden']must now read[class~='max-md:hidden'].
Verify:
rg -n -e "[\"' \x60(]compact:[a-z\[!-]" apps packages -g '*.{ts,tsx,css}'
# Expected: no output
git diff --stat | tail -1
# Expected: about 270 files changed
Out of scope: compact props, compactForLog, compactedAt, the currency compact formatter.
Task 7: Static verification
Depends on: Tasks 1–6 Steps:
- Run the spec's two
rgacceptance checks. - Run the typecheck for all six packages.
- Run Biome on the changed files.
- Run the
@carbon/utilstests.
Verify:
pnpm exec turbo run typecheck --filter=@carbon/utils --filter=@carbon/react --filter=erp --filter=mes --filter=starter --filter=academy
# Expected: all succeed
pnpm exec biome check $(git diff --name-only | grep -E '\.(ts|tsx|css)$')
# Expected: no errors
Task 8: Browser verification
Depends on: Task 7 🛑 Ask the owner first. Steps:
- Open the ERP at 375px: a list page and a record page. Compare with the pre-change build.
- Open the same pages at 900px: the desktop layout shows.
- Reload at 375px with the
viewport=phonecookie: no flash of the desktop layout.