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: max-md: and useViewport()
Status: approved Date: 2026-10-07 Extends:
.ai/specs/2026-10-07-mobile-chrome-structure.md(B3, one compact signal)
TL;DR
compact:classes become Tailwind's ownmax-md:. The query stays the same (width < 48rem).useCompact()anduseIsMobile()become oneuseViewport()→{ isPhone, isTablet, isDesktop }.- The ERP-only
data-compact-uigate goes away, because MES goes responsive on this branch. Compact*components keep their names. "Compact" is a shape that phone and tablet can share.- Tablet is 768–1023px. It keeps the desktop layout for now.
- Phone rendering in the ERP does not change.
Problem
The phone layout is switched by a custom Tailwind variant (compact:) and a hook
(useCompact()). Both only work in apps that set data-compact-ui on <html>.
Today that is only the ERP. The variant is a yes/no switch, so it has no room for
a tablet size.
MES will get its responsive pass on this branch before the PR. After that, both main apps use the phone layout and the per-app gate has no job left. This change:
- replaces
compact:with Tailwind's ownmax-md:(the samewidth < 48remquery); - replaces
useCompact()anduseIsMobile()with oneuseViewport()that returns{ isPhone, isTablet, isDesktop }; - removes the
data-compact-uigate.
"Compact" stays as the name of the component shape (CompactToolbar,
CompactSheet, CompactList …). A compact component can later serve phone and
tablet both; the device choice is made at the call site with useViewport().
Research: N/A. This is an internal rename. The only external fact it depends on is
Tailwind's own max-md: output. Tailwind 4.3.0 compiles max-* to
@media (width < var(--breakpoint-*)) (tailwindcss/dist), and its default
--breakpoint-md is 48rem and --breakpoint-lg is 64rem
(tailwindcss/theme.css:328-329). The repo does not override them.
Goals
- One device API in JS:
useViewport()with three booleans. - Standard Tailwind prefixes in CSS, so nobody has to learn a custom variant.
- Phone rendering in the ERP stays the same, pixel for pixel.
- A tablet size exists in the hook, ready for a later tablet pass.
Non-goals
- No tablet layout. At 768–1023px the ERP keeps the desktop layout, as today.
- No
tablet:custom variant. Tablet styles usemd:max-lg:when they are needed. - No rename of compact components or their shape props (
CompactToolbar,CompactSheet,CompactTabRow,stackOnCompact,compactFooterClassName,useCompactCssVar,useCompactModuleSidebar…). - No
ViewportProviderin MES, academy or starter. The MES responsive pass adds it to MES. - Unrelated "compact" names stay:
compactForLog,compactedAt, the compact currency formatter, and so on.
Design
CSS (packages/config/tailwind/theme.css)
Delete
@custom-variant compact.Every
compact:class becomesmax-md:(about 1,400 classes in about 270 files). This includes the class-name selector inCard.tsx([class~='compact:hidden']→[class~='max-md:hidden']). TS object keys such ascompact: truestay as they are.@utility hit-areastays; its uses becomemax-md:hit-area. Update its comment.@custom-variant hover: remove the:where(html:not([data-compact-ui]))branch. Hover then applies where the pointer can hover, or at 48rem and wider, in every app.The global phone block (
@media (width < 48rem),theme.css:445-463) splits in two:Rule Goes to Why Darker --muted-foregroundin light modetheme.css, selectorhtml:not(.dark)Contrast fix, good for every app .truncatekeepswhite-space: nowraptheme.css, selector.truncateEllipsis fix, good for every app --topbar-height: 52px + safe areaapps/erp/app/styles/tailwind.css, selectorhtmlOnly the ERP reads --topbar-heightSonner toast offset from --content-insetapps/erp/app/styles/tailwind.cssOnly the ERP sets --content-insetBoth new blocks keep the
@media (width < 48rem)wrapper.
Viewport constants (packages/utils/src/viewport.ts)
export type Viewport = "phone" | "tablet" | "desktop";
export const PHONE_QUERY = "(width < 48rem)";
export const TABLET_QUERY = "(48rem <= width < 64rem)";
export const VIEWPORT_HINT_COOKIE = "viewport";
export function getViewportHint(request: Request): Viewport; // cookie, else UA "Mobi" → phone, else desktop
export function viewportHintCookie(viewport: Viewport): string;
These replace COMPACT_QUERY, COMPACT_HINT_COOKIE, getCompactHint and
compactHintCookie. The cookie value is the size name. The old compact cookie
is never read: this branch has not shipped, so no browser has it.
Hook and provider (packages/react/src/Viewport.tsx, was Compact.tsx)
export const ViewportProvider: (p: { initialViewport: Viewport; children }) => JSX.Element;
export function useViewport(): { isPhone: boolean; isTablet: boolean; isDesktop: boolean };
export const HitArea: () => JSX.Element; // unchanged, its classes move to max-md:
- One
useSyncExternalStore. It subscribes to both media queries, and its snapshot is theViewportstring, a stable primitive. The hook derives the three booleans from that one value, so they can never disagree. - Server snapshot: the provider's
initialViewport, else"desktop". That is the oldfalsefor apps with no provider. ViewportProviderwrites the hint cookie on mount and on every size change, asCompactProviderdoes now.- Deleted:
useCompact,useIsMobile,CompactProvider,hooks/useIsMobile.tsand its export fromhooks/index.ts.
Call sites
const isCompact = useCompact()becomesconst { isPhone } = useViewport(), and the localisCompactreferences becomeisPhone. Props namedisCompactthat describe a component's shape keep their name.useIsMobile()callers (Sidebar,FunnelChart, MESactive.tsx/recent.tsx, starterBreadcrumbs.tsx) becomeuseViewport().isPhone.- ERP
root.tsx: removedata-compact-ui;getCompactHint→getViewportHint;CompactProvider initialCompact→ViewportProvider initialViewport.
Behaviour changes (accepted)
- In MES, academy and starter, shared components now take their phone form below 48rem.
Popoverbecomes a bottom sheet, andTabs,Card,Inputand others restyle. Academy usesInput/Popover/Tooltip; starter usesInput. - In those apps, sticky hover highlights no longer show after a tap on phones.
- In those apps, phones also get the darker muted text and the
.truncateellipsis fix. - MES phones show the ERP phone styling until the MES responsive pass.
Design Decisions
| Decision | Choice | Why |
|---|---|---|
| CSS prefix | Tailwind max-md: |
Same query as compact:. With no gate there is nothing custom left |
| Tablet in CSS | md:max-lg:, no custom variant |
Standard Tailwind. Add a variant only if it is used a lot |
| Hook shape | { isPhone, isTablet, isDesktop }, from one size value |
Owner's call: booleans read best in JSX, and one source means no conflicts |
| Tablet range | 48rem ≤ width < 64rem | Tailwind md→lg; iPad portrait is tablet, landscape is desktop |
| Per-app gate | Removed | MES goes responsive on this branch before the PR |
| Component names | Keep Compact* |
"Compact" is a shape that phone and tablet can share; the device choice stays at the call site |
| Cookie value | Size name (phone/tablet/desktop) |
The hook has three sizes; a 1/0 value cannot carry them |
| UA fallback | Mobi → phone, else desktop |
Same as today; tablet uses the desktop layout anyway |
Legacy compact cookie |
Not read | The branch has not shipped |
| File name | Compact.tsx → Viewport.tsx |
The file now holds the device API, not a component shape |
Acceptance criteria
-
rg -e "[\"' \x60]compact:[a-z\[!-]" apps packages -g '*.{ts,tsx,css}'returns nothing. -
rg "useCompact\b|useIsMobile|CompactProvider|data-compact-ui|COMPACT_QUERY|COMPACT_HINT|getCompactHint|compactHintCookie|initialCompact" apps packagesreturns nothing. - Typecheck passes for
@carbon/utils,@carbon/react,erp,mes,starterandacademy; Biome passes. - The ERP at 375px: a list page (for example Sales Orders) and a record page match the pre-change screenshots. At 1280px they also match. (Browser check, only with the owner's go-ahead.)
- The ERP at 900px renders the desktop layout, and
useViewport()reportsisTablet: true. - A first load with the cookie
viewport=phoneserver-renders the phone layout, with no flash of the desktop layout.
Open questions (resolved)
- Rename
compact:tophone:, or use Tailwind'smax-md:? — Answer:max-md:. The gate goes away once MES is responsive on this branch, and thencompact:is justmax-md:. - What happens to the
data-compact-uigate? — Answer: Remove it. Academy/starter side effects and the interim MES styling are accepted. - Hook return shape? — Answer: Booleans
{ isPhone, isTablet, isDesktop }, derived from one size value inside the hook. - Tablet width range? — Answer: 48rem–64rem.
- Rename
Compact*components to Phone/Mobile? — Answer: No. "Compact" names the shape and can cover phone and tablet; only the device API is renamed. - The gate also wraps a global phone CSS block. Where does each rule go? — Answer: The
contrast and truncate fixes apply in every app. The top bar height and the toast offset
move to ERP's
tailwind.css, because only the ERP uses their variables. - Sequencing with the chrome-structure work? — Answer: The owner committed it first; the tree is clean.
Changelog
- 2026-10-07: Draft written after the design discussion.