Skip to content

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.

fix(pwa): reconnect on /health, pin the offline page to its cache, docs and tests

naveenkash0d7fb7f79861
diff --git a/.ai/lessons.md b/.ai/lessons.md
index 1a253d3fee..78d7b3fe01 100644
--- a/.ai/lessons.md
+++ b/.ai/lessons.md
@@ -4049,3 +4049,43 @@ The write was then removed (nothing reads it), so the rail always starts collaps
**Rule:** When the server derives a value for a blank cell, remove that field's `default` from `fieldMappings`, and pin the absence in a test (`shared.method-import-append.test.ts` → "presets no BOM unit and no operation type"). A wizard Default and a server fallback cannot both apply.
**Applies to:** every table in `fieldMappings` (`apps/erp/app/modules/shared/imports.models.ts`) whose importer has a fallback for a blank cell.
+
+## Registering on `load` from entry.client never registers in dev
+
+**Context:** The ERP and MES service workers were registered from `entry.client.tsx` with `window.addEventListener("load", register)`, the pattern most guides show (2026-10-22).
+
+**Problem:** On the dev server React Router imports `entry.client` late: by the time the module runs, the page has already fired `load` (`document.readyState === "complete"`), so the listener never ran and no worker was registered. The offline page never appeared and nothing logged an error.
+
+**Rule:** Register immediately when `document.readyState === "complete"`, and on `load` otherwise. Check `navigator.serviceWorker.getRegistrations()` in the browser after any change to how a worker is registered.
+
+**Applies to:** `apps/erp/app/entry.client.tsx`, `apps/mes/app/entry.client.tsx`; any code in an entry module that waits for `load`.
+
+## A service worker's install-time cache can come out empty and stay empty
+
+**Context:** The ERP worker saves `offline.html` when it installs, and installs anyway when the save fails, so push never depends on it (2026-10-22).
+
+**Problem:** A user toggled offline while an updated worker was installing. The save failed, the new worker activated and deleted the previous cache, and every later offline page load got the browser's "This site can't be reached": the worker had nothing to answer with, and it only reinstalls when its own file changes.
+
+**Rule:** Never trust that install filled a cache. Re-check it from the fetch handler after a page load that reached the network (`ensureOfflinePage`), and give the worker a built-in last-resort response (`fallbackOfflinePage`) so a cache miss never surfaces as the browser's error.
+
+**Applies to:** `apps/{erp,mes}/public/service-worker.js`; any worker that precaches on install.
+
+## Changing a precached file without bumping the cache name changes nothing
+
+**Context:** `offline.html` was edited several times (the game, the text wrapping), and each time existing browsers kept showing the old page (2026-10-22).
+
+**Problem:** A worker saves the file only when it installs, and it reinstalls only when `service-worker.js` itself changes. Editing `offline.html` alone leaves every browser that already has the worker on the old copy, and the self-heal only fills a missing entry, it never replaces one.
+
+**Rule:** Every change to `offline.html` bumps the offline cache in both workers (ERP `OFFLINE_CACHE`, MES `SHELL_CACHE`). `offline-page.test.ts` in each app pins the page's hash to the cache name, so a change that skips the bump fails.
+
+**Applies to:** `apps/{erp,mes}/public/offline.html` and `service-worker.js`.
+
+## Chrome on macOS drops an installed app's Dock badge when its window closes
+
+**Context:** The app icon badge is set by the open tab and by each push (`setAppBadge` in the worker), so it should keep counting while the installed app is closed (2026-10-22).
+
+**Problem:** In Chrome on macOS the badge shows while the app's window is open and disappears when it closes; a push that arrives later, and `setAppBadge` run from the worker's own console, both resolve and draw nothing. Chrome's installed app is a helper process that quits with its window, and the badge belongs to it. The badge also needs macOS notification permission with "Badge app icon" on (System Settings → Notifications → the app).
+
+**Rule:** Do not promise a closed-app badge on macOS Chrome. Test the badge with the app hidden (⌘H), not closed, and test the closed case on a platform meant to keep it (an iPhone Home Screen app) before calling it broken.
+
+**Applies to:** `apps/erp/app/hooks/useAppBadge.ts`, `apps/erp/public/service-worker.js`, the `send-push` badge count.
diff --git a/.ai/specs/2026-10-08-web-push-notifications.md b/.ai/specs/2026-10-08-web-push-notifications.md
index 4dc4cc7b82..7e3b628196 100644
--- a/.ai/specs/2026-10-08-web-push-notifications.md
+++ b/.ai/specs/2026-10-08-web-push-notifications.md
@@ -410,3 +410,4 @@ No change to MES or to `useNotifications`. `AvatarMenu.tsx` is unchanged: sign-o
4. `deriveVapidDetails` has a known-answer test, cross-checked with OpenSSL. A change to the hash, the salt or the info label changes every deployment's key, so the test fails.
- 2026-10-09: Cleanup from self-review. The `"send-push"` entry left the `trigger` map: nothing called it, and only `notify` sends pushes. `pushDeliveryOutcome` lost its `delivered` result, because web-push throws only for a non-2xx status. `supportsPush` moved to `apps/erp/app/utils/push.ts`, so the bell row and the hook share one check. The route's two service-role deletes became `deleteBrowserPushSubscriptions`. The push cookie and the session cookie share one options object.
- 2026-10-09: `apps/erp/public/serviceWorker.js` is deleted, at the user's request. No code registered it. Registered at scope `/`, it would replace `push-worker.js`.
+- 2026-10-22: `push-worker.js` is renamed `service-worker.js` (`SERVICE_WORKER_URL`, `apps/erp/app/utils/service-worker.ts`). It also serves the offline page, so every page load registers it, not only Enable. A browser keeps one registration per scope, and the push subscription with it, so the rename keeps existing subscriptions. Each push now carries `badge`, the unread count for the installed app's icon. See `.claude/rules/service-workers.md`.
diff --git a/.claude/rules/service-workers.md b/.claude/rules/service-workers.md
new file mode 100644
index 0000000000..27275be8c2
--- /dev/null
+++ b/.claude/rules/service-workers.md
@@ -0,0 +1,93 @@
+---
+paths:
+ - "apps/erp/public/service-worker.js"
+ - "apps/mes/public/service-worker.js"
+ - "apps/*/public/offline.html"
+ - "apps/*/public/site.webmanifest"
+ - "apps/erp/app/entry.client.tsx"
+ - "apps/mes/app/entry.client.tsx"
+ - "apps/erp/app/utils/service-worker.ts"
+ - "apps/erp/app/utils/app-badge.ts"
+ - "apps/erp/app/hooks/useAppBadge.ts"
+ - "apps/erp/app/hooks/usePushSubscription.ts"
+ - "packages/jobs/src/inngest/functions/notifications/send-push.ts"
+---
+
+# Service workers, the offline page, the app badge and installing
+
+Each app has ONE worker, `public/service-worker.js`, at scope `/`: a browser keeps
+one registration per scope, so anything a worker does (push, offline, caching) goes
+into that file. Both `entry.client.tsx` files register it on every page load,
+immediately when `document.readyState` is already `complete` (the dev server
+imports the entry after `load`), else on `load`. Workers in `public/` are plain JS:
+no Biome, no typecheck, no bundling. Check them with `node --check`.
+
+## ERP (`apps/erp/public/service-worker.js`)
+
+- Was `push-worker.js` until it took on the offline page. `SERVICE_WORKER_URL`
+ (`apps/erp/app/utils/service-worker.ts`) is the one URL; `usePushSubscription`
+ registers the same URL before subscribing. Registering a new script URL at the
+ same scope keeps the registration and its push subscription.
+- **Fetch:** page loads only (`mode === "navigate"`, GET). Navigation preload is on;
+ the response passes through untouched, a server error page included. Only a
+ network failure answers `offline.html` from `OFFLINE_CACHE`, else
+ `fallbackOfflinePage()` (built in), never the browser's error. Assets, loader data
+ and API calls never reach the worker: a failed client-side navigation shows React
+ Router's own error, not the offline page.
+- **Cache:** `offline.html` only. Saved at install (a failed save still installs, so
+ push never depends on it) and re-saved by `ensureOfflinePage()` after any page load
+ that reached the network.
+- **Push:** `setBadge(payload.badge)`, then the notification (no `tag` passed to
+ `showNotification`, see `.ai/lessons.md`), icon `/icon-192.png`; `notificationclick`
+ focuses a controlled Carbon window and navigates it, else `clients.openWindow`;
+ `pushsubscriptionchange` re-saves through `PUT /api/push-subscription`.
+
+## MES (`apps/mes/public/service-worker.js`)
+
+Same navigate/offline behaviour, plus `ASSET_CACHE`: `/assets/*` (content-hashed
+build files) cache-first, trimmed to 400 entries; icons, logos and the manifest
+stale-while-revalidate. Same-origin only, so a CDN asset base (`ASSETS_URL`) is
+untouched. It never caches a page, loader data or a private file, so nothing
+outlives a sign-out. `SHELL_CACHE` (the offline page) and `ASSET_CACHE` have their
+own versions.
+
+## offline.html
+
+One page, copied into both apps' `public/`, kept identical. Self-contained (inline
+CSS and script, nothing to fetch). It reloads on the `online` event and, every 10 s
+while the device reports online, when `GET /health` answers 2xx: `online` never
+fires when the Wi-Fi stayed up but Carbon was unreachable, and `/health` answers 503
+while the database is down. It skips that check at its own address. The forklift
+game opens only from **Play while you wait**.
+
+**Every change to `offline.html` bumps both offline caches** (ERP `OFFLINE_CACHE`,
+MES `SHELL_CACHE`): the worker saves the page only when it installs, and installs
+only when its own file changes. `apps/{erp,mes}/app/utils/offline-page.test.ts` pin
+the page's sha256 to the cache name, so a change without a bump fails.
+
+## App icon badge
+
+The installed app's icon shows the user's unread top-level notifications (no digest
+children) across their EMPLOYEE companies, not just the current one.
+
+- Open tab: `useAppBadge` (mounted by the desktop bell and the mobile dock, never
+ both) counts on mount and again 500 ms after any change on the user's notification
+ topic; `employeeCompanyIds` and `setAppBadge` live in `~/utils/app-badge.ts`.
+- Closed app: `send-push` step `count-unread` counts the same set with the service
+ role and sends `badge` in the payload (omitted when the read fails; the push
+ still goes). The worker sets it.
+- Sign-out: the login page clears it.
+- Platform limits: macOS needs notification permission with "Badge app icon" for the
+ app. Chrome on macOS drops the badge when the app's window closes, and a later push
+ does not bring it back.
+
+## Installing
+
+`site.webmanifest` (ERP, MES): `id`, `start_url` and `scope` are `/` (Chrome's
+address-bar install needs `start_url`; `id` keeps later manifest changes on the same
+installed app). Icons: `icon-192.png` / `icon-512.png` (`any`, transparent: the
+tab favicon's dark mark), `icon-maskable-512.png` (white, mark at 60 % for Android's
+crop) and an opaque white `apple-touch-icon.png` (iOS fills transparency with black).
+All are rendered from `carbon-favicon.svg`, and academy, starter and docs carry the
+same files. A web app gets one icon: no manifest field switches it with light or dark
+mode.
diff --git a/AGENTS.md b/AGENTS.md
index d0ce12a685..ef729d6cce 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -140,6 +140,7 @@ IMPORTANT: Before any research or coding, match the task to this table. A single
| Redis (shared dev) | `.claude/rules/dev-shared-redis.md` |
| Client cache (`cachedClientLoader`, `useLoaderQuery`, `useAction`) | `.claude/rules/clientAction-patterns.md` + `packages/query/AGENTS.md` |
| Realtime (broadcast, `handle.realtime`, live lists, change log) | `.claude/rules/realtime-system.md` + `packages/query/AGENTS.md` |
+| Service workers, offline page, app icon badge, installing the app | `.claude/rules/service-workers.md` |
| Event triggers and interceptors (attachments manifest) | `.claude/rules/authz-manifest.md` |
| **Architecture** | |
| General coding conventions | `.claude/rules/coding-conventions.md` |
diff --git a/apps/academy/public/apple-touch-icon.png b/apps/academy/public/apple-touch-icon.png
index f63749a97c..2fdd26bca7 100644
Binary files a/apps/academy/public/apple-touch-icon.png and b/apps/academy/public/apple-touch-icon.png differ
diff --git a/apps/academy/public/icon-192.png b/apps/academy/public/icon-192.png
new file mode 100644
index 0000000000..1a89c615b1
Binary files /dev/null and b/apps/academy/public/icon-192.png differ
diff --git a/apps/academy/public/icon-512.png b/apps/academy/public/icon-512.png
new file mode 100644
index 0000000000..aa79060217
Binary files /dev/null and b/apps/academy/public/icon-512.png differ
diff --git a/apps/academy/public/icon-maskable-512.png b/apps/academy/public/icon-maskable-512.png
new file mode 100644
index 0000000000..ec10514d9f
Binary files /dev/null and b/apps/academy/public/icon-maskable-512.png differ
diff --git a/apps/academy/public/site.webmanifest b/apps/academy/public/site.webmanifest
index 4962607769..c373ba1bcc 100644
--- a/apps/academy/public/site.webmanifest
+++ b/apps/academy/public/site.webmanifest
@@ -1 +1 @@
-{"name": "", "short_name": "", "icons": [{"src": "/carbon-mark-dark.png", "type": "image/png", "sizes": "any"}], "theme_color": "#ffffff", "background_color": "#ffffff", "display": "standalone"}
\ No newline at end of file
+{"name": "", "short_name": "", "icons": [{"src": "/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any"}, {"src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any"}, {"src": "/icon-maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"}], "theme_color": "#ffffff", "background_color": "#ffffff", "display": "standalone"}
\ No newline at end of file
diff --git a/apps/erp/app/hooks/useAppBadge.ts b/apps/erp/app/hooks/useAppBadge.ts
index 74c2147ccc..e7e9b89c37 100644
--- a/apps/erp/app/hooks/useAppBadge.ts
+++ b/apps/erp/app/hooks/useAppBadge.ts
@@ -6,6 +6,7 @@ import { getLogger } from "@carbon/logger";
import { useTopic } from "@carbon/query";
import { useCarbon, useRouteData } from "@carbon/react";
import { useCallback, useEffect, useMemo, useRef } from "react";
+import { employeeCompanyIds, setAppBadge } from "~/utils/app-badge";
import { path } from "~/utils/path";
const logger = getLogger("erp", "useappbadge");
@@ -13,18 +14,6 @@ const logger = getLogger("erp", "useappbadge");
// A bulk change (mark all read) broadcasts once per row; count once.
const RECOUNT_DELAY_MS = 500;
-// Sets or clears the installed app's icon badge. Only an installed app shows
-// one; elsewhere the call is missing or does nothing.
-export function setAppBadge(count: number) {
- if (typeof navigator === "undefined" || !("setAppBadge" in navigator)) {
- return;
- }
- const result =
- count > 0 ? navigator.setAppBadge(count) : navigator.clearAppBadge();
- // Refused (Safari without notification permission): no badge is fine.
- result.catch(() => undefined);
-}
-
// The installed app's icon badge: the user's unread notifications in every
// company they work in. The bell counts one company; the icon stands for the
// whole app, and a push from any company sets it the same way (send-push
@@ -37,14 +26,7 @@ export function useAppBadge({ userId }: { userId: string }) {
}>(path.to.authenticatedRoot);
// A string, so a revalidation that returns the same companies is no change.
const companyIds = useMemo(
- () =>
- (shell?.companies ?? [])
- .flatMap((company) =>
- company.role === "employee" && company.companyId
- ? [company.companyId]
- : []
- )
- .join(","),
+ () => employeeCompanyIds(shell?.companies ?? []).join(","),
[shell?.companies]
);
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
diff --git a/apps/erp/app/routes/_public+/login.tsx b/apps/erp/app/routes/_public+/login.tsx
index 5499f88f5e..c91efedb15 100644
--- a/apps/erp/app/routes/_public+/login.tsx
+++ b/apps/erp/app/routes/_public+/login.tsx
@@ -68,8 +68,8 @@ import type {
MetaFunction
} from "react-router";
import { data, useFetcher, useLoaderData, useSearchParams } from "react-router";
-import { setAppBadge } from "~/hooks/useAppBadge";
import type { Result } from "~/types";
+import { setAppBadge } from "~/utils/app-badge";
import { path } from "~/utils/path";
export const meta: MetaFunction = () => {
diff --git a/apps/erp/app/utils/app-badge.test.ts b/apps/erp/app/utils/app-badge.test.ts
new file mode 100644
index 0000000000..1609c0ea90
--- /dev/null
+++ b/apps/erp/app/utils/app-badge.test.ts
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { employeeCompanyIds, setAppBadge } from "./app-badge";
+
+describe("employeeCompanyIds", () => {
+ it("keeps only the companies the user works in", () => {
+ expect(
+ employeeCompanyIds([
+ { companyId: "c1", role: "employee" },
+ { companyId: "c2", role: "customer" },
+ { companyId: "c3", role: "supplier" },
+ { companyId: null, role: "employee" },
+ { companyId: "c4", role: "employee" }
+ ])
+ ).toEqual(["c1", "c4"]);
+ });
+});
+
+describe("setAppBadge", () => {
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ function stubNavigator() {
+ const badge = {
+ setAppBadge: vi.fn(() => Promise.resolve()),
+ clearAppBadge: vi.fn(() => Promise.resolve())
+ };
+ vi.stubGlobal("navigator", badge);
+ return badge;
+ }
+
+ it("shows a count above zero", () => {
+ const badge = stubNavigator();
+ setAppBadge(3);
+ expect(badge.setAppBadge).toHaveBeenCalledWith(3);
+ expect(badge.clearAppBadge).not.toHaveBeenCalled();
+ });
+
+ it("clears the badge at zero, rather than showing a dot", () => {
+ const badge = stubNavigator();
+ setAppBadge(0);
+ expect(badge.clearAppBadge).toHaveBeenCalled();
+ expect(badge.setAppBadge).not.toHaveBeenCalled();
+ });
+
+ it("does nothing where the browser has no badge", () => {
+ vi.stubGlobal("navigator", {});
+ expect(() => setAppBadge(3)).not.toThrow();
+ });
+
+ it("swallows a refusal", async () => {
+ vi.stubGlobal("navigator", {
+ setAppBadge: () => Promise.reject(new Error("NotAllowedError")),
+ clearAppBadge: () => Promise.resolve()
+ });
+ expect(() => setAppBadge(3)).not.toThrow();
+ // Let the rejection settle: an unhandled one would fail the run.
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ });
+});
diff --git a/apps/erp/app/utils/app-badge.ts b/apps/erp/app/utils/app-badge.ts
new file mode 100644
index 0000000000..3440f3d84b
--- /dev/null
+++ b/apps/erp/app/utils/app-badge.ts
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+// Sets or clears the installed app's icon badge. Only an installed app shows
+// one; elsewhere the call is missing or does nothing. Chrome on macOS drops the
+// badge when the app's window closes, and a push cannot bring it back until
+// the app opens again.
+export function setAppBadge(count: number) {
+ if (typeof navigator === "undefined" || !("setAppBadge" in navigator)) {
+ return;
+ }
+ const result =
+ count > 0 ? navigator.setAppBadge(count) : navigator.clearAppBadge();
+ // Refused (Safari without notification permission): no badge is fine.
+ result.catch(() => undefined);
+}
+
+// The companies whose notifications the badge counts: the ones the user works
+// in. A customer or supplier membership has no ERP notifications, and the push
+// side (the send-push "count-unread" step) counts the same set.
+export function employeeCompanyIds(
+ companies: { companyId: string | null; role: string | null }[]
+): string[] {
+ return companies.flatMap((company) =>
+ company.role === "employee" && company.companyId ? [company.companyId] : []
+ );
+}
diff --git a/apps/erp/app/utils/offline-page.test.ts b/apps/erp/app/utils/offline-page.test.ts
new file mode 100644
index 0000000000..ad3147b9e3
--- /dev/null
+++ b/apps/erp/app/utils/offline-page.test.ts
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { createHash } from "node:crypto";
+import { readFileSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+import { describe, expect, it } from "vitest";
+
+const read = (path: string) =>
+ readFileSync(fileURLToPath(new URL(path, import.meta.url)), "utf8");
+
+// The service worker saves public/offline.html when it installs, and it only
+// reinstalls when service-worker.js changes. So a change to offline.html must
+// come with a new cache name, or every browser keeps showing the old page.
+//
+// When this fails because offline.html changed:
+// 1. bump the offline cache in BOTH apps' public/service-worker.js
+// (ERP OFFLINE_CACHE, MES SHELL_CACHE);
+// 2. copy the page to the other app, so ERP and MES serve the same page;
+// 3. pin the new hash and cache name here AND in the other app's copy of this
+// test (apps/{erp,mes}/app/utils/offline-page.test.ts).
+const OFFLINE_PAGE_SHA256 =
+ "82d00b39fa70f0c33ec54fa8b98480bc42cfb4dfd37d28decd89181b8ff3f2de";
+const OFFLINE_CACHE = "erp-offline-v5";
+
+describe("offline page", () => {
+ it("ships with the cache version its worker was bumped for", () => {
+ const page = read("../../public/offline.html");
+ expect(createHash("sha256").update(page).digest("hex")).toBe(
+ OFFLINE_PAGE_SHA256
+ );
+ expect(read("../../public/service-worker.js")).toContain(
+ `const OFFLINE_CACHE = "${OFFLINE_CACHE}";`
+ );
+ });
+});
diff --git a/apps/erp/public/offline.html b/apps/erp/public/offline.html
index 1f43e9ff74..74902a7fec 100644
--- a/apps/erp/public/offline.html
+++ b/apps/erp/public/offline.html
@@ -148,15 +148,15 @@
// "online" never fires when the device kept its network but Carbon
// could not be reached (the server, or the internet behind the Wi-Fi):
- // ask Carbon itself every few seconds. offline.html is a static file, so
- // the check costs the server nothing; the service workers pass it
- // straight to the network.
- // Not at its own address: there it is not standing in for a page, and
- // the check would succeed and reload it forever.
+ // ask Carbon itself every few seconds. /health answers 200 only once
+ // the app and its database are up (503 while the database is down), so
+ // a static file a CDN still serves cannot reload this into an error.
+ // The service workers pass it straight to the network. Not at its own
+ // address: there it stands in for no page, and would reload forever.
setInterval(() => {
if (!navigator.onLine || location.pathname === "/offline.html") return;
- fetch("/offline.html", { method: "HEAD", cache: "no-store" }).then(
- () => location.reload(),
+ fetch("/health", { cache: "no-store" }).then(
+ (response) => response.ok && location.reload(),
() => undefined
);
}, 10000);
diff --git a/apps/erp/public/service-worker.js b/apps/erp/public/service-worker.js
index 7c7d983c8e..964ff060a9 100644
--- a/apps/erp/public/service-worker.js
+++ b/apps/erp/public/service-worker.js
@@ -13,7 +13,7 @@
// offline.html is saved only when this worker installs, and it installs only
// when this file changes: bump the version whenever offline.html changes, or
// browsers keep the old page.
-const OFFLINE_CACHE = "erp-offline-v4";
+const OFFLINE_CACHE = "erp-offline-v5";
const OFFLINE_URL = "/offline.html";
// Only offline.html is cached, so a new version can take over at once instead
@@ -88,7 +88,7 @@ function fallbackOfflinePage() {
'<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Offline | Carbon</title>' +
'<body style="margin:0;min-height:100vh;display:grid;place-items:center;font-family:system-ui,sans-serif;text-align:center">' +
"<main><h1 style=\"font-size:1.25rem\">You're offline</h1><p>Carbon reloads the page when the connection is back.</p></main>" +
- '<script>addEventListener("online",()=>location.reload());setInterval(()=>navigator.onLine&&fetch("/offline.html",{method:"HEAD",cache:"no-store"}).then(()=>location.reload(),()=>{}),10000)</script>';
+ '<script>addEventListener("online",()=>location.reload());setInterval(()=>navigator.onLine&&fetch("/health",{cache:"no-store"}).then(r=>r.ok&&location.reload(),()=>{}),10000)</script>';
return new Response(html, {
headers: { "Content-Type": "text/html; charset=utf-8" }
});
diff --git a/apps/mes/app/utils/offline-page.test.ts b/apps/mes/app/utils/offline-page.test.ts
new file mode 100644
index 0000000000..69929046aa
--- /dev/null
+++ b/apps/mes/app/utils/offline-page.test.ts
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { createHash } from "node:crypto";
+import { readFileSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+import { describe, expect, it } from "vitest";
+
+const read = (path: string) =>
+ readFileSync(fileURLToPath(new URL(path, import.meta.url)), "utf8");
+
+// The service worker saves public/offline.html when it installs, and it only
+// reinstalls when service-worker.js changes. So a change to offline.html must
+// come with a new cache name, or every browser keeps showing the old page.
+//
+// When this fails because offline.html changed:
+// 1. bump the offline cache in BOTH apps' public/service-worker.js
+// (ERP OFFLINE_CACHE, MES SHELL_CACHE);
+// 2. copy the page to the other app, so ERP and MES serve the same page;
+// 3. pin the new hash and cache name here AND in the other app's copy of this
+// test (apps/{erp,mes}/app/utils/offline-page.test.ts).
+const OFFLINE_PAGE_SHA256 =
+ "82d00b39fa70f0c33ec54fa8b98480bc42cfb4dfd37d28decd89181b8ff3f2de";
+const OFFLINE_CACHE = "mes-shell-v5";
+
+describe("offline page", () => {
+ it("ships with the cache version its worker was bumped for", () => {
+ const page = read("../../public/offline.html");
+ expect(createHash("sha256").update(page).digest("hex")).toBe(
+ OFFLINE_PAGE_SHA256
+ );
+ expect(read("../../public/service-worker.js")).toContain(
+ `const SHELL_CACHE = "${OFFLINE_CACHE}";`
+ );
+ });
+});
diff --git a/apps/mes/public/offline.html b/apps/mes/public/offline.html
index 1f43e9ff74..74902a7fec 100644
--- a/apps/mes/public/offline.html
+++ b/apps/mes/public/offline.html
@@ -148,15 +148,15 @@
// "online" never fires when the device kept its network but Carbon
// could not be reached (the server, or the internet behind the Wi-Fi):
- // ask Carbon itself every few seconds. offline.html is a static file, so
- // the check costs the server nothing; the service workers pass it
- // straight to the network.
- // Not at its own address: there it is not standing in for a page, and
- // the check would succeed and reload it forever.
+ // ask Carbon itself every few seconds. /health answers 200 only once
+ // the app and its database are up (503 while the database is down), so
+ // a static file a CDN still serves cannot reload this into an error.
+ // The service workers pass it straight to the network. Not at its own
+ // address: there it stands in for no page, and would reload forever.
setInterval(() => {
if (!navigator.onLine || location.pathname === "/offline.html") return;
- fetch("/offline.html", { method: "HEAD", cache: "no-store" }).then(
- () => location.reload(),
+ fetch("/health", { cache: "no-store" }).then(
+ (response) => response.ok && location.reload(),
() => undefined
);
}, 10000);
diff --git a/apps/mes/public/service-worker.js b/apps/mes/public/service-worker.js
index 4cbe45c836..fe0bdf4d6a 100644
--- a/apps/mes/public/service-worker.js
+++ b/apps/mes/public/service-worker.js
@@ -11,7 +11,7 @@
// when this file changes: bump SHELL_CACHE whenever offline.html changes, or
// browsers keep the old page. The asset cache has its own version: build files
// are named by their content, so an offline.html change keeps them.
-const SHELL_CACHE = "mes-shell-v4";
+const SHELL_CACHE = "mes-shell-v5";
const ASSET_CACHE = "mes-assets-v1";
const OFFLINE_URL = "/offline.html";
@@ -135,7 +135,7 @@ function fallbackOfflinePage() {
'<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Offline | Carbon</title>' +
'<body style="margin:0;min-height:100vh;display:grid;place-items:center;font-family:system-ui,sans-serif;text-align:center">' +
"<main><h1 style=\"font-size:1.25rem\">You're offline</h1><p>Carbon reloads the page when the connection is back.</p></main>" +
- '<script>addEventListener("online",()=>location.reload());setInterval(()=>navigator.onLine&&fetch("/offline.html",{method:"HEAD",cache:"no-store"}).then(()=>location.reload(),()=>{}),10000)</script>';
+ '<script>addEventListener("online",()=>location.reload());setInterval(()=>navigator.onLine&&fetch("/health",{cache:"no-store"}).then(r=>r.ok&&location.reload(),()=>{}),10000)</script>';
return new Response(html, {
headers: { "Content-Type": "text/html; charset=utf-8" }
});
diff --git a/apps/starter/public/apple-touch-icon.png b/apps/starter/public/apple-touch-icon.png
index f63749a97c..2fdd26bca7 100644
Binary files a/apps/starter/public/apple-touch-icon.png and b/apps/starter/public/apple-touch-icon.png differ
diff --git a/apps/starter/public/icon-192.png b/apps/starter/public/icon-192.png
new file mode 100644
index 0000000000..1a89c615b1
Binary files /dev/null and b/apps/starter/public/icon-192.png differ
diff --git a/apps/starter/public/icon-512.png b/apps/starter/public/icon-512.png
new file mode 100644
index 0000000000..aa79060217
Binary files /dev/null and b/apps/starter/public/icon-512.png differ
diff --git a/apps/starter/public/icon-maskable-512.png b/apps/starter/public/icon-maskable-512.png
new file mode 100644
index 0000000000..ec10514d9f
Binary files /dev/null and b/apps/starter/public/icon-maskable-512.png differ
diff --git a/apps/starter/public/site.webmanifest b/apps/starter/public/site.webmanifest
index c10116451b..078e6e3e56 100644
--- a/apps/starter/public/site.webmanifest
+++ b/apps/starter/public/site.webmanifest
@@ -1 +1 @@
-{"name": "Carbon", "short_name": "Carbon", "icons": [{"src": "/carbon-mark-dark.png", "type": "image/png", "sizes": "any"}], "theme_color": "#ffffff", "background_color": "#ffffff", "display": "standalone"}
\ No newline at end of file
+{"name": "Carbon", "short_name": "Carbon", "icons": [{"src": "/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any"}, {"src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any"}, {"src": "/icon-maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"}], "theme_color": "#ffffff", "background_color": "#ffffff", "display": "standalone"}
\ No newline at end of file
diff --git a/docs/content/docs/reference/notifications.mdx b/docs/content/docs/reference/notifications.mdx
index 7c77de9433..416705de13 100644
--- a/docs/content/docs/reference/notifications.mdx
+++ b/docs/content/docs/reference/notifications.mdx
@@ -45,7 +45,7 @@ Each channel is enabled by default. Turning off a switch mutes only that topic a
## Browser notifications
-Above the grid, the **Browser notifications** card turns them on for the browser you are using. Click **Enable** and allow the browser's prompt. The bell also offers **Enable browser notifications** at the top of the inbox until you enable them or choose **Not now** (it asks once more after 30 days, then stops). Browser notifications are a setting of the browser: once enabled on a computer or phone, whoever signs in there gets their own notifications, from every company they belong to. Signing out — or being signed out — stops the previous user's notifications at once, so a shared computer never shows someone else's. **Disable** turns them off for that browser, for everyone who uses it. On iPhone or iPad, add Carbon to the Home Screen first — Safari offers push only to Home Screen apps. When Carbon is installed as an app (Home Screen, Dock, or an installed browser app), its icon shows how many notifications are unread across all your companies; signing out clears it.
+Above the grid, the **Browser notifications** card turns them on for the browser you are using. Click **Enable** and allow the browser's prompt. The bell also offers **Enable browser notifications** at the top of the inbox until you enable them or choose **Not now** (it asks once more after 30 days, then stops). Browser notifications are a setting of the browser: once enabled on a computer or phone, whoever signs in there gets their own notifications, from every company they belong to. Signing out — or being signed out — stops the previous user's notifications at once, so a shared computer never shows someone else's. **Disable** turns them off for that browser, for everyone who uses it. On iPhone or iPad, add Carbon to the Home Screen first — Safari offers push only to Home Screen apps. When Carbon is installed as an app (Home Screen, Dock, or an installed browser app), its icon shows how many notifications are unread across all your companies; signing out clears it. A Chrome app on a Mac shows the count only while its window is open: closing the window clears it, and a notification that arrives while it is closed does not bring it back.
## Who receives an expiration or reminder
diff --git a/docs/public/apple-touch-icon.png b/docs/public/apple-touch-icon.png
index f63749a97c..2fdd26bca7 100644
Binary files a/docs/public/apple-touch-icon.png and b/docs/public/apple-touch-icon.png differ
diff --git a/docs/public/icon-192.png b/docs/public/icon-192.png
new file mode 100644
index 0000000000..1a89c615b1
Binary files /dev/null and b/docs/public/icon-192.png differ
diff --git a/docs/public/icon-512.png b/docs/public/icon-512.png
new file mode 100644
index 0000000000..aa79060217
Binary files /dev/null and b/docs/public/icon-512.png differ
diff --git a/docs/public/icon-maskable-512.png b/docs/public/icon-maskable-512.png
new file mode 100644
index 0000000000..ec10514d9f
Binary files /dev/null and b/docs/public/icon-maskable-512.png differ
diff --git a/docs/public/site.webmanifest b/docs/public/site.webmanifest
index f141316a96..0685c3589b 100644
--- a/docs/public/site.webmanifest
+++ b/docs/public/site.webmanifest
@@ -3,12 +3,25 @@
"short_name": "Docs",
"icons": [
{
- "src": "/carbon-mark-dark.png",
+ "src": "/icon-192.png",
+ "sizes": "192x192",
"type": "image/png",
- "sizes": "any"
+ "purpose": "any"
+ },
+ {
+ "src": "/icon-512.png",
+ "sizes": "512x512",
+ "type": "image/png",
+ "purpose": "any"
+ },
+ {
+ "src": "/icon-maskable-512.png",
+ "sizes": "512x512",
+ "type": "image/png",
+ "purpose": "maskable"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
-}
\ No newline at end of file
+}