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): clear the badge with no employee company; log MES asset cache failures [preview]

naveenkash639a2a4b4688
diff --git a/apps/erp/app/hooks/useAppBadge.ts b/apps/erp/app/hooks/useAppBadge.ts
index aad721e419..6cec1d5cec 100644
--- a/apps/erp/app/hooks/useAppBadge.ts
+++ b/apps/erp/app/hooks/useAppBadge.ts
@@ -36,8 +36,14 @@ export function useAppBadge({ userId }: { userId: string }) {
const latest = useRef(0);
const recount = useCallback(async () => {
- if (!carbon || !companyIds) return;
+ if (!carbon) return;
const run = ++latest.current;
+ // No company left to count (the last employee membership was removed):
+ // nothing is unread, and the bump above discards a recount still running.
+ if (!companyIds) {
+ setAppBadge(0);
+ return;
+ }
const { count, error } = await carbon
.from("notification")
.select("id", { count: "exact", head: true })
diff --git a/apps/mes/public/service-worker.js b/apps/mes/public/service-worker.js
index b780950a76..78a8555497 100644
--- a/apps/mes/public/service-worker.js
+++ b/apps/mes/public/service-worker.js
@@ -92,7 +92,12 @@ function saveAsset(event, cache, response, { trim = false } = {}) {
cache
.put(event.request, response.clone())
.then(() => (trim ? trimAssets(cache) : undefined))
- .catch(() => undefined)
+ .catch((error) => {
+ console.warn("Failed to cache asset", {
+ path: new URL(event.request.url).pathname,
+ error
+ });
+ })
);
}