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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
perf(ui): stop prefetching a link on press
Sidwebworks6e3bdf7bc698
diff --git a/.ai/lessons.md b/.ai/lessons.mdindex 16f55f176b..3284d24b53 100644--- a/.ai/lessons.md+++ b/.ai/lessons.md@@ -2988,3 +2988,14 @@ tag until proven otherwise.**Rule:** Key anything stored on the device by user as well as company, and empty the in-memory cache when the user changes (`setClientCompanyId(companyId, userId)`). A cache that is only ever patched needs a path that replaces it.**Applies to:** `packages/query/src/useLiveList.tsx`, `packages/query/src/cache.ts`, any new client-side persistence.+++## A prefetch the browser cannot reuse makes the click slower++**Context:** Links prefetched their page's data on hover, then (2026-10-02) on press, to give the click a head start.++**Problem:** Single-fetch `.data` responses carry `cache-control: max-age=0, must-revalidate` and no validator, so the browser never serves the click from the prefetched response: both requests reach the server. Chrome also holds a second request for a URL until the first one's response arrives (its HTTP cache admits one writer per URL). The click's request therefore waited behind the prefetch: 781 ms against 518 ms median click-to-page in production, and two same-URL `fetch` calls took 572 / 923 ms where two `cache: "no-store"` ones took 615 / 585 ms.++**Rule:** Do not start a second request for a URL that is already in flight, and do not prefetch a response the browser is not allowed to reuse. Before adding a prefetch, read the response's `cache-control`. Measure a prefetch by click-to-page time, not by whether the request was sent.++**Applies to:** `packages/react/src/PrefetchLink.tsx`; any `<Link prefetch>` or `PrefetchPageLinks`; a revalidation started while a navigation to the same URL is loading.diff --git a/packages/react/AGENTS.md b/packages/react/AGENTS.mdindex fbd898452c..02528fe4b5 100644--- a/packages/react/AGENTS.md+++ b/packages/react/AGENTS.md@@ -42,7 +42,7 @@ import { Button, Card, HStack, VStack, IconButton, cn } from "@carbon/react";- **Layout**: `VStack` / `HStack` with numeric `spacing` prop (maps to `space-y-*`/`space-x-*`)- **Overlays**: `Drawer`, `Modal`, `ModalDrawer` (unified drawer/modal), `BottomSheet`, `Popover`. A controlled `Modal`/`Drawer` with no `onOpenChange` cannot be dismissed and shows no close button; never pass a handler that does nothing (`no-noop-open-change` check). A route rendered as a modal or drawer closes with `useCloseRoute()` (back when this tab has history, else the parent route), not `navigate(-1)`- **App nav**: `NavRail` is the primary left nav of both the ERP and MES shells (56px icon rail, expands after a 150ms mouse hover or when pinned via `SidebarProvider` (⌘B unless `keyboardShortcut={false}`, as in the ERP), left drawer below md that closes itself on navigation). Optional `header` (use `NavRailBrand` for a logo + name) and `footer` slots; `NavRailGroup` adds a titled section that shows as a divider while collapsed. Entries are `NavRailItem` (a button, or `asChild` for a trigger/link) and `NavRailLink`; `label` is a string and doubles as the accessible name. A Radix menu/popover opened from a `NavRailItem` keeps the rail as it was (open or collapsed) until it closes. Render inside `SidebarProvider`; the shadcn-style `Sidebar*` primitives remain for other layouts-- **Links that prefetch**: `PrefetchLink` is a React Router `Link` that prefetches its destination when the pointer goes down on it. Use it instead of `<Link prefetch="intent">`, which prefetches on a 100 ms hover and so runs a page's loaders for every row the mouse passes over. `NavRailLink` and both apps' `Hyperlink` already use it+- **Links**: `PrefetchLink` is the app's React Router `Link` and the one place that decides whether links prefetch. Today they do not: page data is served `max-age=0`, so a prefetched response is never reused, and the browser holds the click's request for the same URL behind it (about 260 ms slower per click than no prefetch, measured in production). Use it instead of `<Link prefetch="intent">`. `NavRailLink` and both apps' `Hyperlink` already use it- **Data**: `Table` (TanStack), chart components via sub-exports (`@carbon/react/Chart`)- **Rich text**: `@carbon/react/Editor` and `@carbon/react/RichText` (wraps `@carbon/tiptap`)- **Error boundary**: `@carbon/react/ErrorBoundary` — `RouteErrorBoundary` (exported as `ErrorBoundary` from a module layout so a failed loader shows inside the app shell) and `RootErrorBoundary` (drop-in root `ErrorBoundary` for RR v7 that maps 404 / other HTTP / thrown `Error` to a styled screen) plus its parts (`ErrorScreen`, `GlitchHeading`, `StatusReadout`, `MagneticLink`, `NoiseOverlay`). Wrap it in the app's `Document` and pass `env` so `window.env` is set (the client crashes hydration otherwise). Copy is intentionally hardcoded English, not i18n.diff --git a/packages/react/src/PrefetchLink.tsx b/packages/react/src/PrefetchLink.tsxindex a6228e193c..88b286c233 100644--- a/packages/react/src/PrefetchLink.tsx+++ b/packages/react/src/PrefetchLink.tsx@@ -4,55 +4,24 @@"use client";-import { forwardRef, useState } from "react";+import { forwardRef } from "react";import type { LinkProps } from "react-router";-import { Link, PrefetchPageLinks, useHref } from "react-router";--const ABSOLUTE_URL = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;+import { Link } from "react-router";/**- * A `Link` that prefetches its destination when the pointer goes down on it.+ * The app's `Link`: the one place that decides whether links prefetch. Today+ * they do not.*- * `prefetch="intent"` prefetches on a 100 ms hover, so moving the mouse down a- * list ran every hovered page's loaders for a click that mostly never came. A- * press is a commitment: it costs one request, and the page gets the time- * between press and release as a head start. Chromium serves the click from- * the prefetched response; a browser that does not reuse it makes one extra- * request per click, never one per hover.+ * Page data is served `max-age=0`, so the browser cannot answer a click from a+ * prefetched response. It also holds a second request for a URL until the+ * first one's response arrives, so a prefetch started on hover or on press+ * made the click's own request wait behind it: about 260 ms slower per click+ * than no prefetch, measured in production.** Use this instead of `<Link prefetch="intent">`.*/export const PrefetchLink = forwardRef<HTMLAnchorElement,Omit<LinkProps, "prefetch">->(({ onPointerDown, ...props }, ref) => {- const href = useHref(props.to, { relative: props.relative });- // A new key remounts the prefetch tags, so each press prefetches again.- const [presses, setPresses] = useState(0);- const canPrefetch =- props.to !== "#" &&- !(typeof props.to === "string" && ABSOLUTE_URL.test(props.to));-- return (- <>- <Link- ref={ref}- {...props}- onPointerDown={(event) => {- onPointerDown?.(event);- // A modified or non-primary press opens a new tab or a menu: the- // page being prefetched would not be the one that uses it.- const plain =- event.button === 0 &&- !event.metaKey &&- !event.ctrlKey &&- !event.shiftKey &&- !event.altKey;- if (plain && canPrefetch) setPresses((n) => n + 1);- }}- />- {presses > 0 && <PrefetchPageLinks key={presses} page={href} />}- </>- );-});+>((props, ref) => <Link ref={ref} {...props} />);PrefetchLink.displayName = "PrefetchLink";