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
refactor: trim redundant comments from font code
Sidwebworkse72a512df6b6
diff --git a/.github/workflows/check.yml b/.github/workflows/check.ymlindex 3fb9d0a7c0..e96b84e20f 100644--- a/.github/workflows/check.yml+++ b/.github/workflows/check.yml@@ -32,9 +32,7 @@ jobs:packages/*/node_moduleskey: node-modules-${{ hashFiles('pnpm-lock.yaml') }}- # Always run install (not just on cache miss) so the root postinstall- # runs in every job — it generates packages/documents/src/pdf/fonts.data.ts- # (gitignored), which typecheck/build need. node_modules cache keeps it fast.+ # Always install so the postinstall generates the gitignored font data.- run: pnpm install --frozen-lockfilelint:@@ -59,9 +57,7 @@ jobs:packages/*/node_moduleskey: node-modules-${{ hashFiles('pnpm-lock.yaml') }}- # Always run install (not just on cache miss) so the root postinstall- # runs in every job — it generates packages/documents/src/pdf/fonts.data.ts- # (gitignored), which typecheck/build need. node_modules cache keeps it fast.+ # Always install so the postinstall generates the gitignored font data.- run: pnpm install --frozen-lockfile- run: pnpm exec biome check@@ -88,9 +84,7 @@ jobs:packages/*/node_moduleskey: node-modules-${{ hashFiles('pnpm-lock.yaml') }}- # Always run install (not just on cache miss) so the root postinstall- # runs in every job — it generates packages/documents/src/pdf/fonts.data.ts- # (gitignored), which typecheck/build need. node_modules cache keeps it fast.+ # Always install so the postinstall generates the gitignored font data.- run: pnpm install --frozen-lockfile- run: pnpm run typegen@@ -118,9 +112,7 @@ jobs:packages/*/node_moduleskey: node-modules-${{ hashFiles('pnpm-lock.yaml') }}- # Always run install (not just on cache miss) so the root postinstall- # runs in every job — it generates packages/documents/src/pdf/fonts.data.ts- # (gitignored), which typecheck/build need. node_modules cache keeps it fast.+ # Always install so the postinstall generates the gitignored font data.- run: pnpm install --frozen-lockfile- run: pnpm run lingui:check@@ -147,9 +139,7 @@ jobs:packages/*/node_moduleskey: node-modules-${{ hashFiles('pnpm-lock.yaml') }}- # Always run install (not just on cache miss) so the root postinstall- # runs in every job — it generates packages/documents/src/pdf/fonts.data.ts- # (gitignored), which typecheck/build need. node_modules cache keeps it fast.+ # Always install so the postinstall generates the gitignored font data.- run: pnpm install --frozen-lockfile- run: pnpm testdiff --git a/apps/erp/app/routes/file+/job+/$jobId.traveler[.]pdf.tsx b/apps/erp/app/routes/file+/job+/$jobId.traveler[.]pdf.tsxindex 5a6c47f581..dcc3d681f3 100644--- a/apps/erp/app/routes/file+/job+/$jobId.traveler[.]pdf.tsx+++ b/apps/erp/app/routes/file+/job+/$jobId.traveler[.]pdf.tsx@@ -186,9 +186,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {: undefined;const showFooter = resolved.footerSectionId !== null;- // Fonts are registered up-front by ensureFont (above). getSafeFontFamily falls- // back to Helvetica for any unregistered family so react-pdf never throws- // "Font family not registered".const styles = StyleSheet.create({body: {fontFamily: getSafeFontFamily(resolved.settings.fontFamily),diff --git a/packages/documents/scripts/generate-fonts.mjs b/packages/documents/scripts/generate-fonts.mjsindex 790c46f667..6237240e64 100644--- a/packages/documents/scripts/generate-fonts.mjs+++ b/packages/documents/scripts/generate-fonts.mjs@@ -1,19 +1,10 @@-// Generates src/pdf/fonts.data.ts: the document fonts offered in the template-// editor, embedded as base64 woff data URIs so react-pdf registers them-// in-process with NO network at render time (the old runtime fetch to Google-// Fonts was the source of "Font family not registered" crashes on Vercel).+// Generates src/pdf/fonts.data.ts — the editor's body fonts as base64 woff data+// URIs from @fontsource/* (OFL/Apache), registered in-process with no network at+// render. Runs on the root postinstall + turbo build task; gitignored output.//-// Bytes come from the @fontsource/* packages (OFL/Apache, redistributable).-//-// FORMAT = woff (NOT woff2): react-pdf preloads every registered font, and this-// fontkit's woff2/brotli decoder corrupts shared state when many woff2 fonts are-// decoded in one process → "Offset is outside the bounds of the DataView" at-// embed. woff (zlib/tiny-inflate) is stateless and decodes all families fine.-// (Verified: all 8 families render with woff; woff2 crashes once all are registered.)-//-// Runs automatically on the root `postinstall` and the turbo `build` task-// (output is gitignored). Run manually to refresh:-// pnpm --filter @carbon/documents build+// woff, NOT woff2: react-pdf preloads every registered font, and its fontkit's+// woff2/brotli decoder corrupts shared state across many decodes → DataView range+// errors at embed. woff (zlib) is stateless.import { createRequire } from "node:module";import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";import { dirname, join } from "node:path";@@ -23,9 +14,8 @@ const require = createRequire(import.meta.url);const here = dirname(fileURLToPath(import.meta.url));const OUT = join(here, "..", "src", "pdf", "fonts.data.ts");-// The "latin" subset covers basic + Western European text and keeps the bundle-// small. Family list mirrors DOCUMENT_FONTS in template/schema.ts (Google fonts-// only — Helvetica/Times/Courier are PDF built-ins, Inter is the default body).+// "latin" subset = Western European, keeps the bundle small. Mirrors the bundled+// fonts in DOCUMENT_FONTS (template/schema.ts).const SUBSET = "latin";const FAMILIES = [{ family: "Inter", pkg: "@fontsource/inter", weights: [300, 400, 500, 700, 900] },@@ -39,12 +29,11 @@ const FAMILIES = [];function filesDir(pkg) {- // Locate the package's files/ dir on disk. fs ignores the package's "exports"- // map (which can block require.resolve of ./package.json or ./files/*), so we- // probe the likely install locations directly, then fall back to require.+ // Probe install dirs via fs (which ignores the package's "exports" map, unlike+ // require.resolve), then fall back to require.const candidates = [- join(here, "..", "node_modules", pkg, "files"), // pnpm: documents' own node_modules- join(here, "..", "..", "..", "node_modules", pkg, "files"), // hoisted root+ join(here, "..", "node_modules", pkg, "files"),+ join(here, "..", "..", "..", "node_modules", pkg, "files"),];for (const c of candidates) {if (existsSync(c)) return c;@@ -53,11 +42,6 @@ function filesDir(pkg) {return join(dirname(pkgJson), "files");}-/**- * Locate the woff for one (id, subset, weight); fall back to a dir scan.- * woff (NOT woff2) — react-pdf only supports TTF/WOFF, and its woff2 decoder- * corrupts state across many fonts (see header note).- */function findWoff(dir, id, weight) {const exact = join(dir, `${id}-${SUBSET}-${weight}-normal.woff`);if (existsSync(exact)) return exact;diff --git a/packages/documents/src/pdf/components/Template.tsx b/packages/documents/src/pdf/components/Template.tsxindex fda6624e86..bcc1f78c83 100644--- a/packages/documents/src/pdf/components/Template.tsx+++ b/packages/documents/src/pdf/components/Template.tsx@@ -49,9 +49,6 @@ const Template = ({typeof headerContent === "object" &&Array.isArray(headerContent.content) &&headerContent.content.length > 0;- // All document fonts are bundled and registered in-process; getSafeFontFamily- // falls back to Helvetica if an unregistered family is requested so react-pdf- // never throws "Font family not registered".const safeFontFamily = getSafeFontFamily(fontFamily);const styles = StyleSheet.create({diff --git a/packages/documents/src/pdf/fonts.ts b/packages/documents/src/pdf/fonts.tsindex 544099e302..00a870d7b8 100644--- a/packages/documents/src/pdf/fonts.ts+++ b/packages/documents/src/pdf/fonts.ts@@ -1,31 +1,15 @@import { Font } from "@react-pdf/renderer";import { BUNDLED_FONTS } from "./fonts.data";-/**- * Document fonts for PDFs. Every Google font offered in the template editor is- * bundled into the package as base64 woff (`fonts.data.ts`, generated by- * `pnpm --filter @carbon/documents build`) and registered in-process — there- * is NO network at render time. (The previous approach fetched Google's CSS at- * render, which failed intermittently on Vercel and crashed with- * "Font family not registered: <font>".)- *- * Format is woff, not woff2: react-pdf only supports TTF/WOFF, and this fontkit's- * woff2/brotli decoder corrupts shared state when many woff2 fonts are decoded in- * one process (react-pdf preloads every registered font) → DataView range errors- * at embed. woff (zlib) is stateless and decodes all families reliably.- *- * Helvetica / Times-Roman / Courier are PDF standard fonts and need no registration.- */+// Fonts are bundled as base64 woff (fonts.data.ts, built by+// `pnpm --filter @carbon/documents build`) and registered in-process — no network+// at render. woff, NOT woff2: react-pdf supports only TTF/WOFF, and its fontkit's+// woff2/brotli decoder corrupts shared state when many woff2 fonts are decoded in+// one process, throwing DataView range errors at embed.-/** PDF standard fonts — usable without registration. */export const BUILT_IN_FONTS = ["Helvetica", "Times-Roman", "Courier"];-/**- * Inter fallback via remote TTF URLs, used ONLY when Inter is not present in the- * bundled data — i.e. before the generator has been run. Once bundled, Inter is- * registered from local woff with no network. Kept so the default body font- * still renders on a fresh checkout.- */+// Used only before fonts.data.ts is generated, so the default still renders.const INTER_URL_FALLBACK = {family: "Inter",fonts: [@@ -53,11 +37,6 @@ const INTER_URL_FALLBACK = {let registered = false;-/**- * Register every bundled document font with react-pdf. Idempotent and- * synchronous: bundled fonts are base64 woff decoded in-process, so this never- * hits the network and never fails. Safe to call on every render.- */export function registerDocumentFonts(): void {if (registered) return;registered = true;@@ -65,30 +44,19 @@ export function registerDocumentFonts(): void {for (const { family, fonts } of BUNDLED_FONTS) {Font.register({ family, fonts });}-- // Pre-generation safety net: keep the default (Inter) working until the- // bundled data has been generated.if (!BUNDLED_FONTS.some((f) => f.family === "Inter")) {Font.register(INTER_URL_FALLBACK);}}-/**- * Back-compat entry point. Routes call `await ensureFont(settings.fontFamily)`- * before render; registration is now up-front and local, so the `family` arg is- * ignored — everything is registered at once. Kept async so existing call sites- * don't change.- */+// Back-compat: routes await ensureFont(family) before render, but fonts are now all+// registered up front, so the arg is ignored.export async function ensureFont(_family?: string): Promise<void> {registerDocumentFonts();}-/**- * Resolve a requested font family to one that is safe to render: the family- * itself when it is a PDF built-in or has been registered, otherwise "Helvetica".- * Never returns an unregistered family, so react-pdf cannot throw- * "Font family not registered".- */+// Falls back to Helvetica for an unregistered family so react-pdf never throws+// "Font family not registered".export function getSafeFontFamily(family: string | undefined | null): string {registerDocumentFonts();if (!family) return "Helvetica";diff --git a/packages/documents/src/template/schema.ts b/packages/documents/src/template/schema.tsindex 85c94df45c..c151d0a9aa 100644--- a/packages/documents/src/template/schema.ts+++ b/packages/documents/src/template/schema.ts@@ -303,18 +303,13 @@ export const themeSchema = z.object({text: z.string().regex(HEX_COLOR).default(DEFAULT_THEME.text)});-/**- * Document body fonts. Inter + the Google families are bundled and registered- * in-process (pdf/fonts.ts + pdf/fonts.data.ts); Helvetica/Times/Courier are- * react-pdf built-in PDF standard fonts (no registration needed).- */+// Body fonts offered in the editor. Helvetica/Times/Courier are PDF built-ins; the+// rest are bundled (see pdf/fonts.ts).export const DOCUMENT_FONTS = [- // Bundled (base64 woff, registered in-process — see pdf/fonts.ts).{ value: "Inter", label: "Inter", kind: "Sans" },{ value: "Helvetica", label: "Helvetica", kind: "Sans" },{ value: "Times-Roman", label: "Times", kind: "Serif" },{ value: "Courier", label: "Courier", kind: "Mono" },- // Google fonts — bundled as base64 woff (see pdf/fonts.ts + fonts.data.ts).{ value: "Roboto", label: "Roboto", kind: "Sans" },{ value: "Open Sans", label: "Open Sans", kind: "Sans" },{ value: "Lato", label: "Lato", kind: "Sans" },