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: stop re-running layout loaders on every navigation (#1799)
Sid77a8d2bdfa24
diff --git a/.ai/lessons.md b/.ai/lessons.mdindex 5544256c47..902d42404a 100644--- a/.ai/lessons.md+++ b/.ai/lessons.md@@ -2647,3 +2647,28 @@ tiebreak (a label, a sort order, then the id). Never rely on insertion order sur**Applies to:** any list ordered by `createdAt` whose rows are written together — RPCs,Kysely transactions, `insertInto(...).values([...])`, seeds.++## Single fetch re-runs every matched loader on every navigation++**Context:** A click on a BOM node under a part (`/x/part/:itemId/make/:makeMethodId.data`)+took 2.8 s in production. The Vercel log showed ~68 PostgREST calls for that one click; about+10 belonged to the page being opened.++**Problem:** React Router 7 single fetch passes `defaultShouldRevalidate = true` for every+GET navigation, so every reused ancestor loader re-runs unless its route exports+`shouldRevalidate`. The app shell (`x+/_layout.tsx`, ~20 queries plus an auth round-trip)+only opted out for same-pathname navigations, and the part layouts not at all. The burst is+what makes each call slow: the first concurrent wave ran ~200 ms per call, later ones 30–60 ms.++**Rule:** A layout loader with children exports `shouldRevalidate` and re-runs only when what+it reads changes — `isUnaffectedByNavigation(args, { params, search })` from `@carbon/utils`,+naming the route and search params the loader reads. Mutations and+`useRevalidator().revalidate()` still reach it. Data in a shell loader that does not gate+rendering is returned as a promise and read with `useResolved` (`~/hooks/useResolved`), never+awaited.++**Applies to:** every route with children under `apps/erp/app/routes/x+` and+`apps/mes/app/routes/x+` — `_layout.tsx`, `$id.tsx` with tabs, and list pages that parent a+drawer (`foo.tsx` + `foo.new.tsx`). A list loader reads the whole query string, so it passes+`search: "all"`. A loader that reads the pathname, a cookie or a header must not use the+helper.diff --git a/.ai/research/2026-10-01-route-loader-audit.md b/.ai/research/2026-10-01-route-loader-audit.mdnew file mode 100644index 0000000000..c779e2accf--- /dev/null+++ b/.ai/research/2026-10-01-route-loader-audit.md@@ -0,0 +1,303 @@+# Route loader audit — where the requests go++Date: 2026-10-01.+Trigger: one BOM click on `/x/part/:itemId/make/:makeMethodId.data` took 2.8 s in+production and fired ~68 PostgREST calls, about 10 of which belonged to the page.++## Status (same day)++Fixed in the same change:++- Both app shells re-run only after a mutation; the ERP shell streams the hub, changelog+ and audit-log flag; the MES shell loads in one wave.+- 186 UI layout loaders under `x+` export `shouldRevalidate` (10 by hand, 176 by codemod).+ The tables in B are the **before** picture.+- `companyPlan` is cached in Redis (60 s, cleared by the Stripe sync) and memoized per+ read request; the changelog entry is cached in Redis (5 min).+- Change notice layout: impact fan-out streams, per-item reads run in one wave, the two+ tag lists are read once instead of once per item.+- Independent serial reads parallelised in `settings+/billing`, `workflows+/runs.$runId`+ and both tracked-pick loaders.++Left open, with reasons, in "Left open" at the end.++## How this was measured++- **Static.** A script walked every file under `apps/erp/app/routes` and+ `apps/mes/app/routes` and read each `loader` body. "Reads" is the number of+ service-function calls (`get*`, `is*`, `find*`, …) plus direct `.from()` /+ `.rpc()` calls written **in the loader body**.+- **It undercounts.** A service function that fans out internally counts as one.+ `part+/$itemId.tsx` scores 14 here and issued about 40 requests in the Vercel log.+ Treat the numbers as a ranking, not a request count.+- **Runtime.** The two Vercel logs for the part route are the only measured data:+ first concurrent wave ~200 ms per call, later calls 30–60 ms, and 1.3–1.8 s per+ call under load.+- "Layout" means the route has child routes: a `_layout.tsx`, or `foo.tsx` with+ `foo.*.tsx` siblings.++## Headline facts++| Fact | Value |+|---|---|+| Route files (ERP / MES) | 1530 / 101 |+| Routes with a loader (ERP / MES) | 864 / 48 |+| Reads written directly in loaders | 2336 (median 1 per loader) |+| Loaders with 10+ reads / 5+ reads | 50 / 135 |+| Layout loaders | 215 |+| Layout loaders with no `shouldRevalidate` | 196 |+| `requirePermissions` call sites in routes | 1839 — one per loader. Claims and the Supabase client are already memoized per read request (`oncePerRead` / `oncePerRequest` in `@carbon/logger`), so this costs a session parse each, not a Redis read each |+| Loaders with 3+ serial awaits and no `Promise.all` | 52 |+| Loaders that await inside a loop | 15 |+| ERP `api+` loaders / with a `clientLoader` cache | 157 / 27 |+| `count: "exact"` in service queries | 154 |+| `select("*")` in service queries | 480 |++## A. Why every ancestor re-runs++React Router 7.18 single fetch passes `defaultShouldRevalidate = true` on every GET+navigation (`singleFetchLoaderNavigationStrategy`). A reused ancestor loader re-runs+unless its route exports `shouldRevalidate`.++| Loader | Reads | Before this branch | Now |+|---|---|---|---|+| ERP shell `x+/_layout.tsx` | ~22 + auth round-trip | re-ran on every pathname change | re-runs only after a mutation |+| MES shell `mes: x+/_layout.tsx` | 15 by this count + auth round-trip | re-ran on every pathname change | re-runs only after a mutation |+| `part` / `material` / `tool` / `consumable` / `service` `$itemId.tsx` + `_layout.tsx` | ~40 for a part | re-ran on every tab and BOM click | skip unless `itemId` / `methodId` change |+| The 196 layouts in B | see B | re-ran on every child navigation | 176 skip unless their params or query string change; 20 left (see "Left open") |++## B. Layout loaders that re-run on every child navigation++Fix for each: `shouldRevalidate` using `isUnaffectedByNavigation(args, { params, search })`+from `@carbon/utils`, naming the params and search params the loader reads.++### B1. Detail layouts (`$id.tsx` with child tabs) — 73 routes, 314 direct reads++| Route | Reads | Serial awaits |+|---|---|---|+| `x+/items+/change-notice+/$id.tsx` | 24 | 6 |+| `x+/quote+/$quoteId.tsx` | 13 | 4 |+| `x+/assembly+/$id.tsx` | 12 | 0 |+| `x+/purchase-order+/$orderId.tsx` | 11 | 1 |+| `x+/inspection+/$id.tsx` | 11 | 1 |+| `x+/sales-order+/$orderId.tsx` | 11 | 1 |+| `x+/supplier-quote+/$id.tsx` | 11 | 3 |+| `x+/payments+/$paymentId.tsx` | 10 | 3 |+| `x+/sales-invoice+/$invoiceId.tsx` | 10 | 1 |+| `x+/receipt+/$receiptId.tsx` | 9 | 3 |+| `x+/purchase-invoice+/$invoiceId.tsx` | 9 | 0 |+| `x+/inventory-count+/$id.tsx` | 9 | 1 |+| `api+/integrations.$id.connect.ts` | 8 | 2 |+| `x+/templates+/$type.tsx` | 8 | 0 |+| `x+/job+/$jobId.tsx` | 8 | 1 |+| `x+/issue+/$id.tsx` | 8 | 0 |+| `x+/supplier+/$supplierId.tsx` | 6 | 0 |+| `x+/maintenance+/$dispatchId.tsx` | 6 | 0 |+| `mes: x+/dispatch.$dispatchId.tsx` | 6 | 2 |+| `x+/shipment+/$shipmentId.tsx` | 5 | 1 |+| `x+/purchasing-rfq+/$rfqId.tsx` | 5 | 1 |+| `x+/customer+/$customerId.tsx` | 5 | 0 |+| `x+/invoicing+/charges.$id.tsx` | 5 | 1 |+| `share+/customer.$id.tsx` | 5 | 2 |+| `x+/picking-list+/$pickingListId.tsx` | 4 | 0 |+| `x+/sales-rfq+/$rfqId.tsx` | 4 | 2 |+| `x+/journal-entry+/$journalEntryId.tsx` | 4 | 2 |+| `x+/part+/$itemId.sales.tsx` | 4 | 0 |+| `x+/tool+/$itemId.purchasing.tsx` | 3 | 0 |+| `x+/tool+/$itemId.purchasing.$supplierPartId.tsx` | 3 | 1 |++The other 43 have 3 or fewer direct reads each.++### B2. List pages that parent a drawer (`foo.tsx` + `foo.new.tsx` / `foo.$id.tsx`) — 109 routes, 239 direct reads++Opening or closing the drawer changes the pathname, so the table query behind it runs again.++| Route | Reads | Serial awaits |+|---|---|---|+| `x+/priority+/people.tsx` | 20 | 3 |+| `x+/priority+/operations.tsx` | 10 | 4 |+| `x+/inventory+/quantities.tsx` | 8 | 3 |+| `x+/inventory+/storage-units.tsx` | 6 | 5 |+| `x+/priority+/dates.tsx` | 6 | 2 |+| `x+/reports+/inventory-valuation.tsx` | 5 | 2 |+| `x+/settings+/printing.tsx` | 5 | 0 |+| `x+/invoicing+/payables.tsx` | 5 | 2 |+| `x+/invoicing+/receivables.tsx` | 5 | 2 |+| `x+/users+/employees.tsx` | 4 | 0 |+| `x+/inventory+/kanbans.tsx` | 4 | 2 |+| `x+/sales+/price-list.tsx` | 4 | 0 |+| `x+/purchasing+/planning.tsx` | 4 | 4 |+| `x+/production+/planning.tsx` | 4 | 4 |+| `x+/production+/demand-forecasts.tsx` | 4 | 4 |+| `api+/traceability.sidebar.ts` | 3 | 3 |+| `api+/integrations.ramp.oauth.ts` | 3 | 5 |+| `x+/users+/suppliers.tsx` | 3 | 0 |+| `x+/users+/customers.tsx` | 3 | 0 |+| `x+/documents+/search.tsx` | 3 | 1 |++The other 89 have 3 or fewer direct reads each.++### B3. Module `_layout.tsx` loaders — 14 routes++| Route | Reads | Reads |+|---|---|---|+| `x+/accounting+/_layout.tsx` | 5 | getAccountsList, getBaseCurrency, getCompaniesInGroup, getIntegrationIdsByRole |+| `x+/get-started+/_layout.tsx` | 5 | getImplementationHub, getImplementationCheckStates, getImplementationFieldValues, getImplementationRows, detectImplementationSignals |+| `x+/customer+/_layout.tsx` | 3 | getCustomerTypes, getCustomerStatuses, getShippingTermsList |+| `x+/inventory+/_layout.tsx` | 2 | getUnitOfMeasuresList, getLocationsList |+| `x+/supplier+/_layout.tsx` | 2 | getSupplierTypes, getShippingTermsList |+| `select-company+/_layout.tsx` | 1 | getMESUrl |+| `x+/quote+/_layout.tsx` | 0 | auth only |+| `x+/assembly+/_layout.tsx` | 0 | auth only |+| `x+/inspection+/_layout.tsx` | 0 | auth only |+| `x+/job+/_layout.tsx` | 0 | auth only |+| `x+/invoicing+/_layout.tsx` | 0 | auth only |+| `x+/supplier-quote+/_layout.tsx` | 0 | auth only |+| `x+/person+/_layout.tsx` | 0 | auth only |+| `mes: display+/_layout.tsx` | 0 | auth only |+++Worst single case: `x+/items+/change-notice+/$id.tsx`. Its loader calls+`getPartUsedIn` (about 15 queries) once per affected item, plus a per-item batch, and+it is a layout — so that whole fan-out repeats on every tab click inside a change notice.++## C. Heaviest leaf loaders (not layouts)++| Route | Reads | Serial awaits | Promise.all |+|---|---|---|---|+| `file+/shipment+/$id[.]pdf.tsx` | 35 | 14 | 11 |+| `mes: x+/operation.$operationId.tsx` | 27 | 6 | 3 |+| `x+/settings+/integrations.$id.tsx` | 26 | 16 | 1 |+| `mes: x+/assembly.$operationId.tsx` | 24 | 4 | 4 |+| `x+/scheduling+/forecast.tsx` | 19 | 7 | 3 |+| `file+/quote+/$id[.]pdf.tsx` | 19 | 5 | 2 |+| `x+/traceability+/graph.tsx` | 18 | 12 | 3 |+| `api+/production.kpi.$key.ts` | 17 | 1 | 3 |+| `file+/sales-invoice+/$id[.]pdf.tsx` | 17 | 6 | 2 |+| `mes: x+/inspection.$operationId.tsx` | 17 | 5 | 2 |+| `file+/job+/$jobId.traveler[.]pdf.tsx` | 16 | 15 | 2 |+| `file+/issue+/$id[.]pdf.tsx` | 16 | 8 | 2 |+| `api+/resources.kpi.$key.ts` | 15 | 0 | 5 |+| `api+/quality.kpi.$key.ts` | 15 | 6 | 3 |+| `file+/sales-return-order+/$id[.]pdf.tsx` | 15 | 4 | 2 |+| `file+/purchase-order+/$orderId[.]pdf.tsx` | 15 | 5 | 2 |+| `file+/purchase-return-order+/$id[.]pdf.tsx` | 15 | 4 | 2 |+| `file+/sales-order+/$id[.]pdf.tsx` | 15 | 5 | 2 |+| `share+/quote.$id.tsx` | 15 | 4 | 2 |+| `x+/inventory+/quantities+/$itemId.details.tsx` | 14 | 7 | 4 |+| `x+/quote+/$quoteId.$lineId.details.tsx` | 12 | 4 | 2 |+| `file+/traveler+/$id[.]pdf.tsx` | 12 | 7 | 2 |+| `api+/sales.kpi.$key.ts` | 11 | 0 | 4 |+| `api+/items.$id.$locationId.forecast.ts` | 11 | 3 | 1 |+| `x+/job+/$jobId.details.tsx` | 11 | 3 | 1 |++## D. Waterfalls — 3+ serial awaits and no `Promise.all` (52 loaders)++| Route | Serial awaits | Reads |+|---|---|---|+| `mes: x+/start.$operationId.tsx` | 11 | 10 |+| `api+/integrations.xero.oauth.ts` | 10 | 6 |+| `file+/stock-transfer+/$id.labels[.]pdf.tsx` | 8 | 6 |+| `file+/entity+/$id.labels[.]pdf.tsx` | 7 | 5 |+| `api+/integrations.jira.oauth.ts` | 5 | 5 |+| `file+/stock-transfer+/$id.labels[.]zpl.tsx` | 5 | 5 |+| `download.$token.tsx` | 5 | 3 |+| `api+/integrations.ramp.oauth.ts` | 5 | 3 |+| `api+/integrations.slack.oauth.ts` | 5 | 1 |+| `api+/integrations.quickbooks.oauth.ts` | 4 | 4 |+| `x+/workflows+/runs.$runId.tsx` | 4 | 4 |+| `x+/picking-list+/$pickingListId.tracked.$lineId.tsx` | 4 | 4 |+| `x+/purchasing+/planning.tsx` | 4 | 4 |+| `x+/settings+/billing.tsx` | 4 | 4 |+| `x+/production+/planning.tsx` | 4 | 4 |+| `x+/production+/demand-forecasts.tsx` | 4 | 4 |+| `file+/entity+/$id.labels[.]zpl.tsx` | 4 | 4 |+| `mes: x+/picking.$pickingListId.tracked.$lineId.tsx` | 4 | 4 |+| `x+/inventory+/quantities+/$itemId.tsx` | 4 | 3 |+| `api+/model.artifacts.$modelUploadId.ts` | 4 | 2 |+| `x+/settings+/audit-logs.tsx` | 4 | 2 |+| `x+/sales-invoice+/new.tsx` | 4 | 2 |+| `mes: api+/model.artifacts.$modelUploadId.ts` | 4 | 2 |+| `api+/settings.backup-archive.$file.ts` | 4 | 1 |+| `api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.ts` | 3 | 8 |+| `x+/reports+/purchases.tsx` | 3 | 5 |+| `x+/workflow+/$id.tsx` | 3 | 5 |+| `_public+/login.tsx` | 3 | 5 |+| `mes: _public+/login.tsx` | 3 | 5 |+| `api+/production.release-readiness.ts` | 3 | 4 |++## E. Await inside a loop or `.map(async …)` (15 loaders)++| Route | Reads | Layout |+|---|---|---|+| `x+/items+/change-notice+/$id.tsx` | 24 | yes |+| `file+/job+/$jobId.traveler[.]pdf.tsx` | 16 | |+| `mes: x+/dispatch.$dispatchId.tsx` | 6 | yes |+| `file+/batch+/$id[.]pdf.tsx` | 5 | |+| `file+/kanban+/labels.$action[.]pdf.tsx` | 4 | |+| `api+/integrations.radan.$version.ts` | 3 | |+| `api+/model.download.$modelUploadId.ts` | 3 | |+| `x+/documents+/search.tsx` | 3 | yes |+| `mes: api+/model.download.$modelUploadId.ts` | 3 | |+| `api+/sales-rfq.$rfqId.map-lines.ts` | 2 | |+| `api+/purchase-invoice.$invoiceId.map-lines.ts` | 2 | |+| `api+/settings.backup-summary.ts` | 2 | |+| `api+/model.artifacts.$modelUploadId.ts` | 2 | |+| `mes: api+/model.artifacts.$modelUploadId.ts` | 2 | |+| `api+/settings.backup-archive.$file.ts` | 1 | |+The PDF and label routes (`file+/…`) dominate C and D. They are document renders, not+navigations, so they cost the user a wait on print rather than slowing the app shell.++## F. KV (Redis) caching candidates++Already cached in Redis: user claims, custom-field schemas, company integrations and+their health, company/location time zones, Stripe customer, printer config.++| Read | Call sites | Writers | Why it fits | Catch |+|---|---|---|---|---|+| `companyPlan` (`readCompanyPlan` in `@carbon/ee/plan.server`) | shell + 55 `requireFeature` + 19 `companyHasFeature` | 2 | Service-role read of one row, on every gated loader and action; changes only on a billing event. Seen twice in one request in the log. | Invalidate in the two writers; a stale plan gates or ungates a paying customer, so no long TTL without invalidation. |+| `getChangelogPanelEntry` | every shell load | none in the app (written by the changelog dispatch) | One global row, identical for every user and company. | Needs a short TTL or a delete from the dispatch job. |+| `getCompanySettings` | 87 (66 loaders) | 46 | The most-read row in the app; also read by `getReleaseControl` on every method mutation. Seen twice in one request. | 46 write sites. Route them through one helper that invalidates, or use a short TTL, before caching. |+| `company` row — `getCompany` (44), `getBaseCurrency` (14), `isAuditLogEnabled` (3) | 61 | not counted | Three functions read the same row, often in the same request. | One cached row with field pickers; invalidate on company update. |+| `getFiscalYearSettings`, `getCurrencyByCode` | 12, 17 | settings only | Slow-changing accounting reference data read on posting and report loaders. | Currency is group-scoped — key by `companyGroupId`. |+| `getTagsList` (45), `getLocationsList` (33), `getPaymentTermsList` (14), `getShippingMethodsList` (8), `getUnitOfMeasuresList` (8) | 108 | CRUD routes | Small company lists fetched by many detail and form loaders. | These go through the user's RLS client today. A KV copy bypasses RLS, so confirm every employee may read them first. Most of the cost disappears anyway once the layouts in B stop re-running. |+| Per-user shell reads — `getUser`, `getUserDefaults` (28), `getUserGroups`, `getModulePreferences`, `getCompanies` | shell | account/settings routes | Read on every shell run. | Low value now that the ERP shell only runs after mutations. |++Not a KV problem, but the same symptom — **the same row read more than once in one+request** (from the log: `companySettings` ×2, `companyPlan` ×2, `companies` ×2,+`item` ×6, `makeMethod` ×5). The request-scoped memo for this already exists+(`oncePerRead` in `@carbon/logger/middleware.server`, used for claims); `companyPlan` now+uses it too. It cannot wrap `getCompanySettings` as written, because that lives in a+`.service.ts` that is bundled for the browser.++## G. Other measured or counted costs++| Place | Fact | Fix |+|---|---|---|+| `RealtimeDataProvider.tsx` | Pulls whole tables from the browser on a cold load (`item`, `supplier`, `customer`, `employees`, `itemSupersession`), ~950 ms each when measured 2026-09-18 | Server-provided or paged data (measured on another branch; not re-measured here) |+| ERP `api+` loaders | 130 of 157 have no `clientLoader` cache, so each selector or combobox that loads one refetches | Add the existing `clientLoader` + `window.clientCache` pattern to the reference-list ones |+| List services | 154 queries ask for `count: "exact"`, a second full count per table page | `estimated` or a deferred count on large tables |+| Shell deferral | Still awaited in the ERP shell: companies, plan, custom fields, integrations, company settings, saved views, user, claims, groups, defaults, module preferences, printer routes, ITAR | These gate rendering or are read synchronously app-wide; deferring them needs each consumer changed |++## Left open++| Item | Why it was not changed |+|---|---|+| Company settings in Redis | 46 write sites and no single helper to invalidate from; a stale toggle reads as "the setting didn't save". With the shells and layouts no longer re-running, what remains is one primary-key read per loader that needs it. |+| `count: "exact"` — **done after sign-off** | The 111 paged list queries (those using `setGenericQueryFilters`) now use `LIST_COUNT` (`estimated`): exact up to PostgREST's 1,000 max-rows, planner estimate beyond. The pager decides "next" from the rows returned (`pageBounds`), so a low estimate cannot hide rows. The 45 `head: true` counts and 29 unpaged ones drive logic and stay exact. |+| `clientLoader` caches on 130 `api+` loaders | Each needs its invalidation mapped in every mutation route, or selectors go stale. Needs a per-endpoint pass. |+| Serial awaits in the other ~29 UI loaders | Reviewed: dependent chains (location → periods → data; guard → write → re-read). MES `start`/`end` loaders write as they go. |+| `x+/priority+/people.tsx` | Reads a cookie for its default scope; its only child is an action route, so there is no child navigation to save. |+| `share+/customer.$id.tsx` | Public portal layout; its loader is the access and plan gate, so it stays evaluated on every navigation. |+| `api+` / webhook routes in the "layout" count | Resource routes, not navigations — false positives of the file-name heuristic. |+| N+1 inside `getPartUsedIn` | Still ~15 queries per item; it now streams and no longer repeats per tab click, but batching it across items is its own change. |++## Suggested order (as written before the fixes)++1. MES shell: same change as the ERP shell (one file).+2. `shouldRevalidate` on the B1 detail layouts, top of the table first — change notice,+ quote, assembly, purchase order, inspection, sales order.+3. Cache `companyPlan` and the changelog entry in Redis (few writers, read everywhere).+4. Request-scoped context for session, claims, company settings and plan.+5. `shouldRevalidate` on the B2 list-plus-drawer parents.+6. Company settings in Redis, after its 46 writers go through one helper.diff --git a/.claude/rules/coding-conventions.md b/.claude/rules/coding-conventions.mdindex 8caa9de33b..6b55e774da 100644--- a/.claude/rules/coding-conventions.md+++ b/.claude/rules/coding-conventions.md@@ -100,6 +100,15 @@ MES is lighter: services live under `apps/mes/app/services/`, components underdestructuring `{ client, companyId, userId }` (also `email`, `companyGroupId`).- Loaders/actions return **plain objects** or `data(value, responseInit)`.Do NOT use `json(...)` — that is the old Remix helper and is not the convention here.+- A route with children that has a loader exports `shouldRevalidate`. Single fetch+ re-runs every matched loader on every navigation otherwise. Use+ `isUnaffectedByNavigation(args, { params, search })` from `@carbon/utils`, naming the+ route params the loader reads and either the search params it reads or `search: "all"`+ for a list loader. Shell data that does not gate rendering is returned as a promise.+ Render it through `Await` when it is visible on first paint, so it streams in the+ server HTML (`ImplementationData` in `~/hooks/useImplementationNavItem` is the+ pattern); read it with `useResolved` (`~/hooks/useResolved`) when a late value is+ harmless.- On success an action throws a redirect (`throw redirect(...)`), not `return`.Cached entities add a `clientAction`/`clientLoader` for cache control.diff --git a/apps/erp/app/components/AuditLog/AuditLogDrawer.tsx b/apps/erp/app/components/AuditLog/AuditLogDrawer.tsxindex 3962f5456a..1bc1fc980c 100644--- a/apps/erp/app/components/AuditLog/AuditLogDrawer.tsx+++ b/apps/erp/app/components/AuditLog/AuditLogDrawer.tsx@@ -41,6 +41,7 @@ import {UpgradeOverlayUpgradeButton} from "~/components/UpgradeOverlay";import { usePermissions, useRouteData } from "~/hooks";+import { useResolved } from "~/hooks/useResolved";import { path } from "~/utils/path";import { isEmptyDiffValue } from "./utils";@@ -100,10 +101,10 @@ const AuditLogDrawer = memo(const lastLoadedRef = useRef<string | null>(null);const loadKey = `${entityType}:${entityId}:${companyId}:${recordId ?? ""}`;- const rootRouteData = useRouteData<{ auditLogEnabled: boolean }>(+ const rootRouteData = useRouteData<{ auditLogEnabled: Promise<boolean> }>(path.to.authenticatedRoot);- const auditLogEnabled = rootRouteData?.auditLogEnabled ?? false;+ const auditLogEnabled = useResolved(rootRouteData?.auditLogEnabled, false);const { can } = usePermissions();// Load audit log data when drawer opens or entity changesdiff --git a/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx b/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsxindex 8a68dde602..00ce3ace2a 100644--- a/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx+++ b/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx@@ -33,7 +33,10 @@ import {usePermissions,useSettingsModule} from "~/hooks";-import { useImplementationNavItem } from "~/hooks/useImplementationNavItem";+import {+ getImplementationNavItem,+ ImplementationData+} from "~/hooks/useImplementationNavItem";import {MODULE_GO_TO,MODULE_GO_TO_PREFIX,@@ -52,15 +55,26 @@ import { useNavigationEditMode } from "./useNavigationEditMode";// accent hover instead of the active-tinted one module links use.const ACTION_HOVER = "hover:bg-accent hover:text-accent-foreground";+const renderLink = (link: Authenticated<NavItem>, isActive: boolean) => (+ <NavRailLink+ key={link.name}+ to={link.to}+ icon={<link.icon />}+ label={link.name}+ tag={link.tag}+ external={link.external}+ isActive={isActive}+ />+);+const PrimaryNavigation = () => {- const { t } = useLingui();+ const { t, i18n } = useLingui();const { isMobile } = useSidebar();const permissions = usePermissions();const location = useOptimisticLocation();const currentModule = getModule(location.pathname);const links = useModules();const settingsModule = useSettingsModule();- const implementationNav = useImplementationNavItem();const matchedModules = useMatches().reduce((acc, match) => {const handle = match.handle as { module?: string } | undefined;@@ -113,18 +127,6 @@ const PrimaryNavigation = () => {useSensor(KeyboardSensor));- const renderLink = (link: Authenticated<NavItem>, isActive: boolean) => (- <NavRailLink- key={link.name}- to={link.to}- icon={<link.icon />}- label={link.name}- tag={link.tag}- external={link.external}- isActive={isActive}- />- );-const footer = (<>{settingsModule && !editMode.isEditing@@ -159,9 +161,16 @@ const PrimaryNavigation = () => {footer={footer}>{canSearch && <NavigationSearchButton />}- {!editMode.isEditing && implementationNav- ? renderLink(implementationNav, currentModule === "get-started")- : null}+ {editMode.isEditing ? null : (+ <ImplementationData>+ {(data) => {+ const item = getImplementationNavItem(data, i18n);+ return item+ ? renderLink(item, currentModule === "get-started")+ : null;+ }}+ </ImplementationData>+ )}{editMode.isEditing ? (<DndContextsensors={sensors}diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsxindex f98ae2ef2f..e364c7c2f2 100644--- a/apps/erp/app/components/Table/Table.tsx+++ b/apps/erp/app/components/Table/Table.tsx@@ -356,7 +356,7 @@ const Table = <T extends object>({}, [data.length, withSelectableRows]);/* Pagination */- const pagination = usePagination(count, setRowSelection);+ const pagination = usePagination(count, setRowSelection, data.length);/* Column Visibility */const [columnVisibility, setColumnVisibility] = useState(diff --git a/apps/erp/app/components/Table/components/Pagination/usePagination.tsx b/apps/erp/app/components/Table/components/Pagination/usePagination.tsxindex 2c0c1c6d19..9350606a84 100644--- a/apps/erp/app/components/Table/components/Pagination/usePagination.tsx+++ b/apps/erp/app/components/Table/components/Pagination/usePagination.tsx@@ -6,20 +6,26 @@ import type { RowSelectionState } from "@tanstack/react-table";import type { Dispatch, SetStateAction } from "react";import { flushSync } from "react-dom";import { useUrlParams } from "~/hooks";-import { getPageOffset, getPageSize } from "~/utils/pagination";+import { getPageOffset, getPageSize, pageBounds } from "~/utils/pagination";export function usePagination(- count: number,- setRowSelections: Dispatch<SetStateAction<RowSelectionState>>+ estimatedCount: number,+ setRowSelections: Dispatch<SetStateAction<RowSelectionState>>,+ rowsOnPage: number) {const [params, setParams] = useUrlParams();const pageSize = getPageSize(params);const offset = getPageOffset(params);const pageIndex = Math.floor(offset / pageSize) + 1;+ const { canNextPage, count } = pageBounds({+ count: estimatedCount,+ offset,+ pageSize,+ rowsOnPage+ });const pageCount = Math.ceil(count / pageSize);const canPreviousPage = pageIndex > 1;- const canNextPage = pageIndex < Math.ceil(count / pageSize);const gotoPage = (page: number) => {flushSync(() => {diff --git a/apps/erp/app/hooks/useChangelogPanel.ts b/apps/erp/app/hooks/useChangelogPanel.tsindex 0356a29b42..0ad61e118d 100644--- a/apps/erp/app/hooks/useChangelogPanel.ts+++ b/apps/erp/app/hooks/useChangelogPanel.ts@@ -7,6 +7,7 @@ import { useFetcher } from "react-router";import type { ChangelogPanelEntry } from "~/modules/account";import { changelogFlagKey } from "~/modules/users";import { path } from "~/utils/path";+import { useResolved } from "./useResolved";import { useUser } from "./useUser";// Dismissing sets the user flag `changelog:<slug>`, so it holds on every device;@@ -17,10 +18,10 @@ export function useChangelogPanel(): {dismiss: () => void;} {const { flags } = useUser();- const data = useRouteData<{ changelog?: ChangelogPanelEntry | null }>(- path.to.authenticatedRoot- );- const entry = data?.changelog ?? null;+ const data = useRouteData<{+ changelog?: Promise<ChangelogPanelEntry | null>;+ }>(path.to.authenticatedRoot);+ const entry = useResolved(data?.changelog, null);const flagKey = entry ? changelogFlagKey(entry.slug) : null;const fetcher = useFetcher({ key: "changelog-dismiss" });diff --git a/apps/erp/app/hooks/useImplementationNavItem.tsx b/apps/erp/app/hooks/useImplementationNavItem.tsxindex 9cab097b04..ed7b2c4def 100644--- a/apps/erp/app/hooks/useImplementationNavItem.tsx+++ b/apps/erp/app/hooks/useImplementationNavItem.tsx@@ -14,10 +14,14 @@ import {type Tier} from "@carbon/onboarding";import { useRouteData } from "@carbon/react";+import type { I18n } from "@lingui/core";import { useLingui } from "@lingui/react/macro";+import { type ReactNode, Suspense } from "react";import { LuRocket } from "react-icons/lu";+import { Await } from "react-router";import type { Authenticated, NavItem } from "~/types";import { path } from "~/utils/path";+import { useResolved } from "./useResolved";const NO_SIGNALS = {hasItems: false,@@ -27,7 +31,7 @@ const NO_SIGNALS = {hasTrackedEntity: false};-type AppLayoutData = {+export type ImplementationHubData = {implementationHub: { tier: Tier; status: HubStatus } | null;implementationCheckStates: CheckStateRow[];implementationSignals: Signals | null;@@ -38,26 +42,51 @@ const isFinished = (status: HubStatus) =>// Shared reader: the enrolled hub (a row only exists once the company is// enrolled), or null. Both nav entries below key off this.-function useHub() {+function useImplementationPromise() {+ return useRouteData<{ implementation?: Promise<ImplementationHubData> }>(+ path.to.authenticatedRoot+ )?.implementation;+}++// Rendered through Await so it streams in the server HTML. The last value is+// the fallback, so a revalidation doesn't blank what is on screen.+export function ImplementationData({+ children+}: {+ children: (data: ImplementationHubData) => ReactNode;+}) {+ const promise = useImplementationPromise();+ const last = useResolved(promise, null);+ if (!promise) return null;+ const fallback = <>{last ? children(last) : null}</>;return (- useRouteData<AppLayoutData>(path.to.authenticatedRoot)?.implementationHub ??- null+ <Suspense fallback={fallback}>+ {/* Without errorElement a rejected stream reaches the route error boundary. */}+ <Await resolve={promise} errorElement={fallback}>+ {children}+ </Await>+ </Suspense>);}+function useHub() {+ return useResolved(useImplementationPromise(), null)?.implementationHub;+}+// The pinned "Get Started" primary-nav entry with a remaining-gates badge. Shown// while a hub is still in progress; gone once it's finished (see reopen entry).-export function useImplementationNavItem(): Authenticated<NavItem> | null {- const { i18n } = useLingui();- const data = useRouteData<AppLayoutData>(path.to.authenticatedRoot);- const hub = data?.implementationHub;+export function getImplementationNavItem(+ data: ImplementationHubData,+ i18n: I18n+): Authenticated<NavItem> | null {+ const hub = data.implementationHub;if (!hub || isFinished(hub.status)) return null;const spine = spineForTier(SPINE, hub.tier);const done = gatesDone(spine,- stateMap(data?.implementationCheckStates ?? []),- data?.implementationSignals ?? NO_SIGNALS+ stateMap(data.implementationCheckStates),+ data.implementationSignals ?? NO_SIGNALS);const remaining = spine.length - done;diff --git a/apps/erp/app/hooks/useResolved.ts b/apps/erp/app/hooks/useResolved.tsnew file mode 100644index 0000000000..932848f525--- /dev/null+++ b/apps/erp/app/hooks/useResolved.ts@@ -0,0 +1,35 @@+// 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 { useEffect, useState } from "react";++const settled = new WeakMap<Promise<unknown>, unknown>();++// Unwraps a promise a loader streamed instead of awaiting, keeping the last+// value while a revalidation's replacement is pending.+export function useResolved<T>(+ promise: Promise<T> | null | undefined,+ fallback: T+): T {+ const [value, setValue] = useState<T>(() =>+ promise && settled.has(promise) ? (settled.get(promise) as T) : fallback+ );++ useEffect(() => {+ if (!promise) return;+ let active = true;+ promise.then(+ (resolved) => {+ settled.set(promise, resolved);+ if (active) setValue(resolved);+ },+ () => undefined+ );+ return () => {+ active = false;+ };+ }, [promise]);++ return value;+}diff --git a/apps/erp/app/hooks/useSupplierApprovalRequired.tsx b/apps/erp/app/hooks/useSupplierApprovalRequired.tsxindex 8ed03ed5df..8a3e88f5ad 100644--- a/apps/erp/app/hooks/useSupplierApprovalRequired.tsx+++ b/apps/erp/app/hooks/useSupplierApprovalRequired.tsx@@ -3,22 +3,12 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { useRouteData } from "@carbon/react";-import { useEffect, useState } from "react";import { path } from "~/utils/path";+import { useResolved } from "./useResolved";export function useSupplierApprovalRequired(): boolean {const routeData = useRouteData<{supplierApprovalRequired: Promise<boolean>;}>(path.to.authenticatedRoot);- const [value, setValue] = useState(false);-- useEffect(() => {- routeData?.supplierApprovalRequired- ?.then((v) => setValue(!!v))- ?.catch(() => {- // swallow rejection — surfaces as default `false`- });- }, [routeData?.supplierApprovalRequired]);-- return value;+ return !!useResolved(routeData?.supplierApprovalRequired, false);}diff --git a/apps/erp/app/modules/account/account.server.ts b/apps/erp/app/modules/account/account.server.tsnew file mode 100644index 0000000000..0bcd583374--- /dev/null+++ b/apps/erp/app/modules/account/account.server.ts@@ -0,0 +1,29 @@+// 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 { getCarbonServiceRole } from "@carbon/auth/client.server";+import { redis } from "@carbon/kv";+import {+ type ChangelogPanelEntry,+ getChangelogPanelEntry+} from "./account.service";++const CHANGELOG_CACHE_KEY = "changelog:latest";+const CHANGELOG_CACHE_TTL_SECONDS = 300;++export async function getCachedChangelogPanelEntry(): Promise<ChangelogPanelEntry | null> {+ const cached = await redis.get(CHANGELOG_CACHE_KEY);+ if (cached) return JSON.parse(cached) as ChangelogPanelEntry;++ const entry = await getChangelogPanelEntry(getCarbonServiceRole());+ if (entry) {+ await redis.set(+ CHANGELOG_CACHE_KEY,+ JSON.stringify(entry),+ "EX",+ CHANGELOG_CACHE_TTL_SECONDS+ );+ }+ return entry;+}diff --git a/apps/erp/app/modules/accounting/accounting.service.ts b/apps/erp/app/modules/accounting/accounting.service.tsindex 18f8bb2246..1098e38356 100644--- a/apps/erp/app/modules/accounting/accounting.service.ts+++ b/apps/erp/app/modules/accounting/accounting.service.ts@@ -24,7 +24,7 @@ import { sql } from "kysely";import type { z } from "zod";import { getNextSequence } from "~/modules/settings";import type { GenericQueryFilters } from "~/utils/query";-import { setGenericQueryFilters } from "~/utils/query";+import { LIST_COUNT, setGenericQueryFilters } from "~/utils/query";import { sanitize } from "~/utils/supabase";import type {AnalyticsAccountScope,@@ -1920,7 +1920,7 @@ export async function getAccounts(let query = client.from("account").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyGroupId", companyGroupId).eq("active", true);@@ -3889,7 +3889,7 @@ export async function getPaymentTerms(let query = client.from("paymentTerm").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId).eq("active", true);@@ -4105,7 +4105,7 @@ export async function getCostCenters() {let query = client.from("costCenter")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -4209,7 +4209,7 @@ export async function getProjects() {let query = client.from("project")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId).eq("active", true);@@ -4267,7 +4267,7 @@ export async function getDimensions(let query = client.from("dimension").select("*, dimensionValue(id, name)", {- count: "exact"+ count: LIST_COUNT}).eq("companyGroupId", companyGroupId).eq("active", true);@@ -5083,7 +5083,7 @@ export async function getIntercompanyTransactions(.from("intercompanyTransaction").select("*, sourceCompany:company!intercompanyTransaction_sourceCompanyId_fkey(name), targetCompany:company!intercompanyTransaction_targetCompanyId_fkey(name)",- { count: "exact" }+ { count: LIST_COUNT }).eq("companyGroupId", companyGroupId);@@ -5272,7 +5272,7 @@ export async function getJournalEntries() {let query = client.from("journalEntries")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -5920,7 +5920,7 @@ export async function getFixedAssetClasses(.from("fixedAssetClass").select("id, name, description, depreciationMethod, usefulLifeMonths, residualValuePercent, taxDepreciationMethod, taxUsefulLifeMonths, macrsPropertyClass",- { count: "exact" }+ { count: LIST_COUNT }).eq("companyId", companyId);@@ -5997,7 +5997,7 @@ export async function getFixedAssets(.from("fixedAsset").select("id, fixedAssetId, fixedAssetClassId, name, serialNumber, status, depreciationMethod, acquisitionCost, accumulatedDepreciation, fixedAssetClass:fixedAssetClassId(id, name), location:locationId(id, name)",- { count: "exact" }+ { count: LIST_COUNT }).eq("companyId", companyId);@@ -6309,7 +6309,7 @@ export async function getDepreciationRuns(let query = client.from("depreciationRun").select("id, depreciationRunId, periodEnd, status, postedAt", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);diff --git a/apps/erp/app/modules/documents/documents.service.ts b/apps/erp/app/modules/documents/documents.service.tsindex a3d7c36a75..ea08bdbb4d 100644--- a/apps/erp/app/modules/documents/documents.service.ts+++ b/apps/erp/app/modules/documents/documents.service.ts@@ -9,7 +9,7 @@ import { trigger } from "@carbon/jobs";import type { SupabaseClient } from "@supabase/supabase-js";import type { z } from "zod";import type { GenericQueryFilters } from "~/utils/query";-import { setGenericQueryFilters } from "~/utils/query";+import { LIST_COUNT, setGenericQueryFilters } from "~/utils/query";import { sanitize } from "~/utils/supabase";import { getDocumentType } from "../shared/shared.service";import type {@@ -75,7 +75,7 @@ export async function getDocuments(let query = client.from("documents").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId).eq("active", args.active);diff --git a/apps/erp/app/modules/inventory/inventory.service.ts b/apps/erp/app/modules/inventory/inventory.service.tsindex 844b76786a..c0cf05514a 100644--- a/apps/erp/app/modules/inventory/inventory.service.ts+++ b/apps/erp/app/modules/inventory/inventory.service.ts@@ -307,7 +307,7 @@ export async function getInventoryItems(company_id: companyId},{- count: "exact"+ count: LIST_COUNT});@@ -334,7 +334,7 @@ export async function getInventoryItemsCount(let query = client.from("item").select("id", {- count: "exact"+ count: LIST_COUNT}).neq("itemTrackingType", "Non-Inventory").eq("companyId", companyId);@@ -487,7 +487,7 @@ export async function getKanbans(let query = client.from("kanbans").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId).eq("locationId", locationId);@@ -577,7 +577,7 @@ export async function getStockTransfers(let query = client.from("stockTransfer").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -641,7 +641,7 @@ export async function getReceipts(let query = client.from("receipt").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId).neq("sourceDocumentId", "");@@ -945,7 +945,7 @@ export async function getStorageUnits(// for tree rendering (indentation, hierarchy filters, subtree rollups).let query = client.from("storageUnits_recursive")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId).eq("locationId", locationId);@@ -992,7 +992,7 @@ export async function getStorageUnitRoots() {let query = client.from("storageUnits_recursive")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId).eq("locationId", locationId).eq("depth", 1);@@ -1135,7 +1135,7 @@ export async function getStockMovements(let query = client.from("itemLedgers").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -1166,7 +1166,7 @@ export async function getShipments(let query = client.from("shipment").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId).neq("sourceDocumentId", "");@@ -1311,7 +1311,7 @@ export async function getShippingMethods(let query = client.from("shippingMethod").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId).eq("active", true);@@ -1537,7 +1537,7 @@ export async function getWarehouseTransfers(.select("*, fromLocation:location!fromLocationId(name), toLocation:location!toLocationId(name)",{- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -1736,7 +1736,7 @@ export async function getInventoryCounts() {let query = client.from("inventoryCount")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -1773,7 +1773,7 @@ export async function getInventoryCountLines(// apply the same generic column filters the quantities screen does.let query = client.from("inventoryCountLines")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("inventoryCountId", inventoryCountId).eq("companyId", companyId);@@ -2602,7 +2602,7 @@ export async function getStorageTypes() {let query = client.from("storageType")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -2717,7 +2717,7 @@ export async function getPickingLists(let query = client.from("pickingLists").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);diff --git a/apps/erp/app/modules/invoicing/invoicing.service.ts b/apps/erp/app/modules/invoicing/invoicing.service.tsindex 21f11d9c64..b704fa0101 100644--- a/apps/erp/app/modules/invoicing/invoicing.service.ts+++ b/apps/erp/app/modules/invoicing/invoicing.service.ts@@ -1410,7 +1410,7 @@ export async function getPayments() {let query = client.from("payment")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -1468,7 +1468,7 @@ export async function getCharges() {let query = client.from("charge")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -1517,7 +1517,7 @@ export async function getReimbursements() {let query = client.from("reimbursement")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -3595,7 +3595,7 @@ export async function getMemos() {let query = client.from("memo")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.tsindex 70600053c4..a3853b7016 100644--- a/apps/erp/app/modules/items/items.service.ts+++ b/apps/erp/app/modules/items/items.service.ts@@ -836,7 +836,7 @@ export async function getItemPostingGroups(let query = client.from("itemPostingGroup").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -1384,7 +1384,7 @@ export async function getMaterialDimensions(let query = client.from("materialDimensions").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("isMetric", args?.isMetric ?? false).or(`companyId.eq.${companyId},companyId.is.null`);@@ -1434,7 +1434,7 @@ export async function getMaterialFinishes(let query = client.from("materialFinishes").select("*", {- count: "exact"+ count: LIST_COUNT}).or(`companyId.eq.${companyId},companyId.is.null`);@@ -1481,7 +1481,7 @@ export async function getMaterialForms(let query = client.from("materialForm").select("*", {- count: "exact"+ count: LIST_COUNT}).or(`companyId.eq.${companyId},companyId.is.null`);@@ -1517,7 +1517,7 @@ export async function getMaterialGrades(let query = client.from("materialGrades").select("*", {- count: "exact"+ count: LIST_COUNT}).or(`companyId.eq.${companyId},companyId.is.null`);@@ -1571,7 +1571,7 @@ export async function getMaterialSubstances(let query = client.from("materialSubstance").select("*", {- count: "exact"+ count: LIST_COUNT}).or(`companyId.eq.${companyId},companyId.is.null`);@@ -1620,7 +1620,7 @@ export async function getMethodMaterials(.select("*, item(name, readableIdWithRevision), makeMethod!makeMethodId(item(id, type, name, readableIdWithRevision))",{- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -1681,7 +1681,7 @@ export async function getMethodOperations(.select("*, makeMethod!makeMethodId(item(id, type, name, readableIdWithRevision))",{- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -2358,7 +2358,7 @@ export async function getUnitOfMeasures(let query = client.from("unitOfMeasure").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -5844,7 +5844,7 @@ export async function getMaterialTypes() {let query = client.from("materialTypes")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).or(`companyId.eq.${companyId},companyId.is.null`);if (args?.search) {@@ -6331,7 +6331,7 @@ export async function getChangeNotices() {let query = client.from("changeOrders")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -6563,7 +6563,7 @@ export async function getChangeNoticeTypes() {let query = client.from("changeOrderType")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -7918,7 +7918,7 @@ export async function getChangeNoticeRequiredActions() {let query = client.from("changeOrderRequiredAction")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {diff --git a/apps/erp/app/modules/items/ui/ChangeNotice/ChangeNoticeProperties.tsx b/apps/erp/app/modules/items/ui/ChangeNotice/ChangeNoticeProperties.tsxindex 165e62d220..d922c53063 100644--- a/apps/erp/app/modules/items/ui/ChangeNotice/ChangeNoticeProperties.tsx+++ b/apps/erp/app/modules/items/ui/ChangeNotice/ChangeNoticeProperties.tsx@@ -30,6 +30,7 @@ import { Assignee, EmployeeAvatar } from "~/components";import { Enumerable } from "~/components/Enumerable";import { Combobox, CreatableCombobox } from "~/components/Form";import { usePermissions, useRouteData } from "~/hooks";+import { useResolved } from "~/hooks/useResolved";import type { action } from "~/routes/x+/items+/change-notice+/update";import type { ListItem } from "~/types";import { path } from "~/utils/path";@@ -72,6 +73,8 @@ function PropertiesSection({// route.) Self-contained: reads everything from the $id route loader so// ResizablePanels can render it with only a `key` (mirrors SalesOrderProperties).// Owns its own width / scroll / border / padding.+const NO_IMPACT: ChangeNoticeImpactItem[] = [];+const ChangeNoticeProperties = () => {const { id } = useParams();if (!id) throw new Error("id not found");@@ -84,7 +87,7 @@ const ChangeNoticeProperties = () => {changeNotice: ChangeNotice;types: ListItem[];affectedItems: AffectedItemDraft[];- impactUsedIn: ChangeNoticeImpactItem[];+ impactUsedIn: Promise<ChangeNoticeImpactItem[]>;nonConformanceOptions: {id: string;nonConformanceId: string;@@ -100,7 +103,7 @@ const ChangeNoticeProperties = () => {const changeNotice = routeData?.changeNotice;const types = routeData?.types ?? [];const affectedItems = routeData?.affectedItems ?? [];- const impactUsedIn = routeData?.impactUsedIn ?? [];+ const impactUsedIn = useResolved(routeData?.impactUsedIn, NO_IMPACT);const nonConformanceOptions = routeData?.nonConformanceOptions ?? [];const linkedNonConformance = routeData?.linkedNonConformance ?? null;const isLocked = isChangeNoticeLocked(changeNotice?.status);diff --git a/apps/erp/app/modules/people/people.service.ts b/apps/erp/app/modules/people/people.service.tsindex 9fbedfe49b..3e7ea95ce5 100644--- a/apps/erp/app/modules/people/people.service.ts+++ b/apps/erp/app/modules/people/people.service.ts@@ -13,7 +13,7 @@ import type { DataType } from "~/modules/shared";import type { Employee } from "~/modules/users";import { getEmployees } from "~/modules/users/users.service";import type { GenericQueryFilters } from "~/utils/query";-import { setGenericQueryFilters } from "~/utils/query";+import { LIST_COUNT, setGenericQueryFilters } from "~/utils/query";import { sanitize } from "~/utils/supabase";import type {departmentValidator,@@ -106,7 +106,7 @@ export async function getAttributeCategories(let query = client.from("userAttributeCategory").select("*, userAttribute(id, name, attributeDataType(id))", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId).eq("active", true)@@ -166,7 +166,7 @@ export async function getDepartments(let query = client.from("department").select(`*, department(id, name)`, {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -246,7 +246,7 @@ export async function getHolidays(let query = client.from("holiday").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -377,7 +377,7 @@ export async function getContacts() {let query = client.from("contact")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -420,7 +420,7 @@ export async function getShifts(let query = client.from("shifts").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId).eq("active", true);@@ -986,7 +986,7 @@ export async function getTimecardEntries() {let query = client.from("timeCardEntries")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.tsindex d7b85b0137..5e420d698d 100644--- a/apps/erp/app/modules/production/production.service.ts+++ b/apps/erp/app/modules/production/production.service.ts@@ -1889,7 +1889,7 @@ export async function getJobOperations(.select("*, jobMakeMethod(parentMaterialId, item(readableIdWithRevision))",{- count: "exact"+ count: LIST_COUNT}).eq("jobId", jobId);@@ -2082,7 +2082,7 @@ export async function getProcedures(let query = client.from("procedures").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -2138,7 +2138,7 @@ export async function getProductionEvents(.select("*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableIdWithRevision)))",{- count: "exact"+ count: LIST_COUNT}).in("jobOperationId", jobOperationIds)@@ -2220,7 +2220,7 @@ export async function getProductionPlanning(periods},{- count: "exact"+ count: LIST_COUNT});@@ -2254,7 +2254,7 @@ export async function getProductionProjections(periods},{- count: "exact"+ count: LIST_COUNT});@@ -2292,7 +2292,7 @@ export async function getProductionQuantities(.select("*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableIdWithRevision)))",{- count: "exact"+ count: LIST_COUNT}).in("jobOperationId", jobOperationIds);@@ -2369,7 +2369,7 @@ export async function getScrapReasons() {let query = client.from("scrapReason")- .select("id, name, customFields", { count: "exact" })+ .select("id, name, customFields", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -2403,7 +2403,7 @@ export async function getFailureModes() {let query = client.from("maintenanceFailureMode")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -2454,7 +2454,7 @@ export async function getMaintenanceDispatches() {let query = client.from("maintenanceDispatch")- .select(`*`, { count: "exact" })+ .select(`*`, { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -2546,7 +2546,7 @@ export async function getMaintenanceSchedules() {let query = client.from("maintenanceSchedules")- .select(`*`, { count: "exact" })+ .select(`*`, { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {diff --git a/apps/erp/app/modules/purchasing/purchasing.service.ts b/apps/erp/app/modules/purchasing/purchasing.service.tsindex 4d4cdc6561..612ff9f45d 100644--- a/apps/erp/app/modules/purchasing/purchasing.service.ts+++ b/apps/erp/app/modules/purchasing/purchasing.service.ts@@ -551,7 +551,7 @@ export async function getPurchasingPlanning(periods},{- count: "exact"+ count: LIST_COUNT});@@ -807,7 +807,7 @@ export async function getSupplierQuotes() {let query = client.from("supplierQuotes")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -941,7 +941,7 @@ export async function getSuppliers(let query = client.from("suppliers").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -996,7 +996,7 @@ export async function getSupplierTypes() {let query = client.from("supplierType")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -2566,7 +2566,7 @@ export async function getPurchasingRFQs() {let query = client.from("purchasingRfqs")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {diff --git a/apps/erp/app/modules/quality/quality.service.ts b/apps/erp/app/modules/quality/quality.service.tsindex e98900ede4..aa9c941409 100644--- a/apps/erp/app/modules/quality/quality.service.ts+++ b/apps/erp/app/modules/quality/quality.service.ts@@ -12,7 +12,7 @@ import { parseDate } from "@internationalized/date";import type { PostgrestError, SupabaseClient } from "@supabase/supabase-js";import type { z } from "zod";import type { GenericQueryFilters } from "~/utils/query";-import { setGenericQueryFilters } from "~/utils/query";+import { LIST_COUNT, setGenericQueryFilters } from "~/utils/query";import { sanitize } from "~/utils/supabase";const logger = getLogger("erp", "quality");@@ -270,7 +270,7 @@ export async function getGauges() {let query = client.from("gauges")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -320,7 +320,7 @@ export async function getGaugeCalibrationRecords() {let query = client.from("gaugeCalibrationRecords")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -375,7 +375,7 @@ export async function getGaugeTypes() {let query = client.from("gaugeType")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -409,7 +409,7 @@ export async function getIssues() {let query = client.from("issues")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -981,7 +981,7 @@ export async function getIssueTypes() {let query = client.from("nonConformanceType")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -1004,7 +1004,7 @@ export async function getIssueWorkflows() {let query = client.from("nonConformanceWorkflow")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId).eq("active", true);@@ -1051,7 +1051,7 @@ export async function getQualityActions() {let query = client.from("qualityActions")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -1112,7 +1112,7 @@ export async function getQualityDocuments(let query = client.from("qualityDocuments").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -1176,7 +1176,7 @@ export async function getRequiredActions() {let query = client.from("nonConformanceRequiredAction")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -1224,7 +1224,7 @@ export async function getRisks(let query = client.from("riskRegisters").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -2340,7 +2340,7 @@ export async function getInspections(.from("inspection").select("*, item(readableId, name), supplier(name), inspectionSample(status)",- { count: "exact" }+ { count: LIST_COUNT }).eq("companyId", companyId);@@ -2596,7 +2596,7 @@ export async function getInspectionDocuments() {let query = client.from("inspectionDocuments")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {diff --git a/apps/erp/app/modules/resources/resources.service.ts b/apps/erp/app/modules/resources/resources.service.tsindex ee1fed056e..5297b444b5 100644--- a/apps/erp/app/modules/resources/resources.service.ts+++ b/apps/erp/app/modules/resources/resources.service.ts@@ -11,7 +11,7 @@ import {import type { SupabaseClient } from "@supabase/supabase-js";import type { z } from "zod";import type { GenericQueryFilters } from "~/utils/query";-import { setGenericQueryFilters } from "~/utils/query";+import { LIST_COUNT, setGenericQueryFilters } from "~/utils/query";import { sanitize } from "~/utils/supabase";import type {failureModeValidator,@@ -223,7 +223,7 @@ export async function getAbilities(// rather than embedded, so the read never depends on a view→table embed.let query = client.from("abilities")- .select(`*`, { count: "exact" })+ .select(`*`, { count: LIST_COUNT }).eq("companyId", companyId).eq("active", true);@@ -402,7 +402,7 @@ export async function getFailureModes() {let query = client.from("maintenanceFailureMode")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -443,7 +443,7 @@ export async function getLocations() {let query = client.from("location")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -552,7 +552,7 @@ export async function getMaintenanceDispatches() {let query = client.from("maintenanceDispatch")- .select(`*`, { count: "exact" })+ .select(`*`, { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -580,7 +580,7 @@ export async function getMaintenanceDispatchesByLocation(p_company_id: companyId,p_location_id: locationId},- { count: "exact" }+ { count: LIST_COUNT });if (args?.search) {@@ -643,7 +643,7 @@ export async function getMaintenanceSchedules() {let query = client.from("maintenanceSchedules")- .select(`*`, { count: "exact" })+ .select(`*`, { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -675,7 +675,7 @@ export async function getMaintenanceSchedulesByLocation(p_company_id: companyId,p_location_id: locationId},- { count: "exact" }+ { count: LIST_COUNT });if (args?.search) {@@ -816,7 +816,7 @@ export async function getProcesses() {let query = client.from("processes")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -858,7 +858,7 @@ export async function getSuggestions() {let query = client.from("suggestions")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -1019,7 +1019,7 @@ export async function getTrainings(let query = client.from("trainings").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -1089,7 +1089,7 @@ export async function getWorkCenters(let query = client.from("workCenters").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.tsindex 065a2fa24b..6c5c1f9d98 100644--- a/apps/erp/app/modules/sales/sales.service.ts+++ b/apps/erp/app/modules/sales/sales.service.ts@@ -874,7 +874,7 @@ export async function getCustomers(let query = client.from("customers").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -918,7 +918,7 @@ export async function getCustomerStatuses() {let query = client.from("customerStatus")- .select("id, name, customFields", { count: "exact" })+ .select("id, name, customFields", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -963,7 +963,7 @@ export async function getCustomerTypes() {let query = client.from("customerType")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -999,7 +999,7 @@ export async function getExternalSalesOrderLines("get_sales_order_lines_by_customer_id",{ customer_id: customerId },{- count: "exact"+ count: LIST_COUNT});@@ -1062,7 +1062,7 @@ export async function getNoQuoteReasons() {let query = client.from("noQuoteReason")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -1192,7 +1192,7 @@ export async function getPricingRules() {let query = client.from("pricingRule")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -1931,7 +1931,7 @@ export async function getSalesRFQs() {let query = client.from("salesRfqs")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -2410,7 +2410,7 @@ export async function resolvePriceList(.from("item").select("id, readableId, name, thumbnailPath, itemUnitSalePrice(unitSalePrice), itemCost(itemPostingGroupId)",- { count: "exact" }+ { count: LIST_COUNT }).eq("active", true).in("id", overriddenItemIds);@@ -2696,7 +2696,7 @@ export async function getBaseCatalog(.from("item").select("id, readableId, name, thumbnailPath, itemUnitSalePrice(unitSalePrice), itemCost(itemPostingGroupId)",- { count: "exact" }+ { count: LIST_COUNT }).eq("companyId", companyId).eq("active", true);@@ -3067,7 +3067,7 @@ export async function getCustomerItemPriceOverridesList(customerType:customerTypeId(id, name),item:itemId(id, name, unitSalePrice:itemUnitSalePrice(unitSalePrice))`,- { count: "exact" }+ { count: LIST_COUNT }).eq("companyId", companyId);@@ -6499,7 +6499,7 @@ export async function getReturnReasons() {let query = client.from("returnReason")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {diff --git a/apps/erp/app/modules/settings/settings.service.ts b/apps/erp/app/modules/settings/settings.service.tsindex cfceb856c1..4b7ff869c7 100644--- a/apps/erp/app/modules/settings/settings.service.ts+++ b/apps/erp/app/modules/settings/settings.service.ts@@ -26,7 +26,7 @@ import type { SupabaseClient } from "@supabase/supabase-js";import type { z } from "zod";import type { plmReleaseControl as plmReleaseControlOptions } from "~/modules/items/items.models";import type { GenericQueryFilters } from "~/utils/query";-import { setGenericQueryFilters } from "~/utils/query";+import { LIST_COUNT, setGenericQueryFilters } from "~/utils/query";import { interpolateSequenceDate } from "~/utils/string";import { sanitize } from "~/utils/supabase";import type {@@ -101,7 +101,7 @@ export async function getApiKeys() {let query = client.from("apiKey")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -331,7 +331,7 @@ export async function getCustomFieldsTables(let query = client.from("customFieldTables").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -418,7 +418,7 @@ export async function getSequences(let query = client.from("sequence").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -455,7 +455,7 @@ export async function getItemSerialSequences(let query = client.from("itemSerialSequences").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);@@ -773,7 +773,7 @@ export async function getWebhooks(let query = client.from("webhook").select("*", {- count: "exact"+ count: LIST_COUNT}).eq("companyId", companyId);diff --git a/apps/erp/app/modules/shared/shared.service.ts b/apps/erp/app/modules/shared/shared.service.tsindex c5623e4f61..81bbcec1be 100644--- a/apps/erp/app/modules/shared/shared.service.ts+++ b/apps/erp/app/modules/shared/shared.service.ts@@ -10,7 +10,7 @@ import type {SupabaseClient} from "@supabase/supabase-js";import type { GenericQueryFilters } from "~/utils/query";-import { setGenericQueryFilters } from "~/utils/query";+import { LIST_COUNT, setGenericQueryFilters } from "~/utils/query";import type { PriceBreak, SupplierPriceMap } from "./shared.models";import type { ItemModelUpload } from "./types";@@ -270,7 +270,7 @@ export async function getCustomerPortals() {let query = client.from("externalLink")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId).eq("documentType", "Customer");@@ -537,7 +537,7 @@ export async function getEnforcementRules(): Promise<PostgrestResponse<EnforcementRuleRow>> {let query = client.from("enforcementRule")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId).eq("family", family);diff --git a/apps/erp/app/modules/users/users.service.ts b/apps/erp/app/modules/users/users.service.tsindex 2e59ee3ab5..8de8df349a 100644--- a/apps/erp/app/modules/users/users.service.ts+++ b/apps/erp/app/modules/users/users.service.ts@@ -8,7 +8,7 @@ import { getLogger } from "@carbon/logger";import { datetime } from "@carbon/utils";import type { PostgrestError, SupabaseClient } from "@supabase/supabase-js";import type { GenericQueryFilters } from "~/utils/query";-import { setGenericQueryFilters } from "~/utils/query";+import { LIST_COUNT, setGenericQueryFilters } from "~/utils/query";import type { UserSelectGroupMembers } from "./types";const logger = getLogger("erp", "users");@@ -187,7 +187,7 @@ export async function getCustomers(.select(`active, user!inner(id, fullName, firstName, lastName, email, avatarUrl),customer!inner(name, customerType!left(name))`,- { count: "exact" }+ { count: LIST_COUNT }).eq("companyId", companyId);@@ -251,7 +251,7 @@ export async function getEmployees() {let query = client.from("employees")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args.search) {@@ -291,7 +291,7 @@ export async function getConsoleOperators() {let query = client.from("employees")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId).like("email", "%@console.internal");@@ -323,7 +323,7 @@ export async function getEmployeeTypes() {let query = client.from("employeeType")- .select("*", { count: "exact" })+ .select("*", { count: LIST_COUNT }).eq("companyId", companyId);if (args?.search) {@@ -529,7 +529,7 @@ export async function getSuppliers(.select(`active, user!inner(id, fullName, firstName, lastName, email, avatarUrl),supplier!inner(name, supplierType!left(name))`,- { count: "exact" }+ { count: LIST_COUNT }).eq("companyId", companyId);diff --git a/apps/erp/app/modules/workflows/workflows.service.ts b/apps/erp/app/modules/workflows/workflows.service.tsindex 6cfa9cdc7b..6014255e41 100644--- a/apps/erp/app/modules/workflows/workflows.service.ts+++ b/apps/erp/app/modules/workflows/workflows.service.ts@@ -20,7 +20,7 @@ export async function getWorkflows(.from("workflow").select("id, name, description, ownerId, publishedVersionId, createdAt, updatedAt",- { count: "exact" }+ { count: LIST_COUNT }).eq("companyId", companyId);diff --git a/apps/erp/app/routes/x+/_index.tsx b/apps/erp/app/routes/x+/_index.tsxindex 0d36400995..17b221e7ba 100644--- a/apps/erp/app/routes/x+/_index.tsx+++ b/apps/erp/app/routes/x+/_index.tsx@@ -6,16 +6,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { getCompanyTimeZone } from "@carbon/database";import { CONTROLLED_ENVIRONMENT, getAppUrl } from "@carbon/env";import {- type CheckStateRow,gatesDone,- type HubStatus,labelForTier,nextAction,type Signals,SPINE,spineForTier,- stateMap,- type Tier+ stateMap} from "@carbon/onboarding";import { OnboardingHubSummary } from "@carbon/onboarding/ui";import {@@ -29,8 +26,7 @@ import {TooltipContent,TooltipTrigger,toast,- useOperatingSystem,- useRouteData+ useOperatingSystem} from "@carbon/react";import { datetime, formatRelativeTime } from "@carbon/utils";import { Trans, useLingui } from "@lingui/react/macro";@@ -65,6 +61,10 @@ import {useUser} from "~/hooks";import { useHubDismissed } from "~/hooks/useHubDismissed";+import {+ ImplementationData,+ type ImplementationHubData+} from "~/hooks/useImplementationNavItem";import type { RecentDocument } from "~/hooks/useRecentlyViewed";import { useUIStore } from "~/stores/ui";import type { Authenticated, NavItem } from "~/types";@@ -76,7 +76,7 @@ import { copyToClipboard } from "~/utils/string";const AGENT_WIDGET_COOKIE = "onboardAgentDismissed";// The home page is always accessible. When a hub is active (enrolled and not yet-// finished) it surfaces as a primary-nav item (`useImplementationNavItem`) and a+// finished) it surfaces as a primary-nav item (`getImplementationNavItem`) and a// summary card below — it never replaces the home page for anyone.export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});@@ -108,24 +108,19 @@ const NO_SIGNALS: Signals = {hasTrackedEntity: false};-function useImplementationSummary() {+function ImplementationSummary({ data }: { data: ImplementationHubData }) {const { i18n } = useLingui();- const data = useRouteData<{- implementationHub: { tier: Tier; status: HubStatus } | null;- implementationCheckStates: CheckStateRow[];- implementationSignals: Signals | null;- }>(path.to.authenticatedRoot);const { company } = useUser();const [dismissed, dismiss] = useHubDismissed(company.id);- const hub = data?.implementationHub;+ const hub = data.implementationHub;// Shown only to enrolled companies — a hub row exists once the company// enrolls itself (self-serve from the home page card below).if (!hub || hub.status === "complete" || hub.status === "archived") {return null;}- const map = stateMap(data?.implementationCheckStates ?? []);- const signals = data?.implementationSignals ?? NO_SIGNALS;+ const map = stateMap(data.implementationCheckStates);+ const signals = data.implementationSignals ?? NO_SIGNALS;const spine = spineForTier(SPINE, hub.tier);const done = gatesDone(spine, map, signals);const total = spine.length;@@ -133,28 +128,32 @@ function useImplementationSummary() {if (done === total || dismissed) return null;const next = nextAction(spine, map, signals);- return {- label: i18n._(labelForTier(hub.tier)),- done,- total,- nextLabel: next?.title ? i18n._(next.title) : undefined,- dismiss- };+ return (+ <OnboardingHubSummary+ label={i18n._(labelForTier(hub.tier))}+ done={done}+ total={total}+ nextLabel={next?.title ? i18n._(next.title) : undefined}+ onDismiss={dismiss}+ action={+ <Button asChild>+ <Link to={path.to.getStarted} prefetch="intent">+ Open+ </Link>+ </Button>+ }+ />+ );}export default function AppIndexRoute() {const { greeting, agentDismissed } = useLoaderData<typeof loader>();const modules = useModules();- const implementation = useImplementationSummary();- const layout = useRouteData<{ implementationHub: unknown | null }>(- path.to.authenticatedRoot- );const permissions = usePermissions();const enrollFetcher = useFetcher();// Self-serve: anyone who can update company settings can enroll their// company — no Carbon staff required.- const canEnroll =- permissions.can("update", "settings") && !layout?.implementationHub;+ const canEnroll = permissions.can("update", "settings");return (<div className="relative w-full h-full overflow-hidden">@@ -186,55 +185,49 @@ export default function AppIndexRoute() {/></div></div>- {implementation ? (- <OnboardingHubSummary- label={implementation.label}- done={implementation.done}- total={implementation.total}- nextLabel={implementation.nextLabel}- onDismiss={implementation.dismiss}- action={- <Button asChild>- <Link to={path.to.getStarted} prefetch="intent">- Open- </Link>- </Button>- }- />- ) : null}+ <ImplementationData>+ {(data) => <ImplementationSummary data={data} />}+ </ImplementationData><div className="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8"><div className="lg:col-span-1 order-last lg:order-first">{canEnroll ? (- <enrollFetcher.Form- method="post"- action={path.to.getStartedEnroll}- className="mb-6"- >- <SectionLabel>- <Trans>Implementation Hub</Trans>- </SectionLabel>- <Card className="shadow-none">- <CardContent>- <p className="text-sm text-muted-foreground text-pretty">- <Trans>- Set up your company with a step-by-step implementation- plan covering setup, data, training, and go-live.- </Trans>- </p>- <div>- <Button- className="mt-4"- type="submit"- rightIcon={<LuRocket />}- isLoading={enrollFetcher.state !== "idle"}- isDisabled={enrollFetcher.state !== "idle"}- >- <Trans>Enroll</Trans>- </Button>- </div>- </CardContent>- </Card>- </enrollFetcher.Form>+ <ImplementationData>+ {(data) =>+ data.implementationHub ? null : (+ <enrollFetcher.Form+ method="post"+ action={path.to.getStartedEnroll}+ className="mb-6"+ >+ <SectionLabel>+ <Trans>Implementation Hub</Trans>+ </SectionLabel>+ <Card className="shadow-none">+ <CardContent>+ <p className="text-sm text-muted-foreground text-pretty">+ <Trans>+ Set up your company with a step-by-step+ implementation plan covering setup, data,+ training, and go-live.+ </Trans>+ </p>+ <div>+ <Button+ className="mt-4"+ type="submit"+ rightIcon={<LuRocket />}+ isLoading={enrollFetcher.state !== "idle"}+ isDisabled={enrollFetcher.state !== "idle"}+ >+ <Trans>Enroll</Trans>+ </Button>+ </div>+ </CardContent>+ </Card>+ </enrollFetcher.Form>+ )+ }+ </ImplementationData>) : null}<RecentlyViewed /></div>diff --git a/apps/erp/app/routes/x+/_layout.tsx b/apps/erp/app/routes/x+/_layout.tsxindex 2a75019104..fe39ec01da 100644--- a/apps/erp/app/routes/x+/_layout.tsx+++ b/apps/erp/app/routes/x+/_layout.tsx@@ -13,7 +13,6 @@ import {SESSION_HEARTBEAT_MS,SESSION_IDLE_LOCK_MS} from "@carbon/auth";-import { getCarbonServiceRole } from "@carbon/auth/client.server";import { getCompanyId, setCompanyId } from "@carbon/auth/company.server";import { userHasVerifiedTotpFactor } from "@carbon/auth/mfa.server";import {@@ -45,8 +44,8 @@ import {import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";import {Edition,- isSearchParamOnlyNavigation,- requiresItarEntityCertification+ requiresItarEntityCertification,+ SHELL_MAX_AGE_MS} from "@carbon/utils";import posthog from "posthog-js";import type { ReactNode } from "react";@@ -74,7 +73,7 @@ import TrainingPanel from "~/components/TrainingPanel";import { useIdle, usePermissions, useRecordRecentlyViewed } from "~/hooks";import { useChangelogPanel } from "~/hooks/useChangelogPanel";import { useTrainingPanel } from "~/hooks/useTrainingPanel";-import { getChangelogPanelEntry } from "~/modules/account";+import { getCachedChangelogPanelEntry } from "~/modules/account/account.server";import { AgentRoot } from "~/modules/agent/ui/AgentRoot";import { getOpenClockEntry } from "~/modules/people";import {@@ -97,9 +96,12 @@ import { ERP_URL, MES_URL, path } from "~/utils/path";const log = getLogger("erp", "auth");+// Set from the component when loader data arrives, not in shouldRevalidate:+// link prefetching calls that too.+let shellLoadedAt = Date.now();+export const shouldRevalidate: ShouldRevalidateFunction = ({currentUrl,- nextUrl,formMethod,defaultShouldRevalidate}) => {@@ -114,16 +116,10 @@ export const shouldRevalidate: ShouldRevalidateFunction = ({return true;}- // This loader is the app shell: 16 parallel queries plus an auth round-trip.- // Without this it re-ran on every table filter, sort and page click, none of- // which can change anything it returns.- // NOTE: `useRevalidator().revalidate()` — how the realtime hooks refresh —- // also looks like a same-pathname GET, so the shell does not re-run for- // realtime events either. Leaf loaders still refresh, which is the intent.- // Shell data that must react to a realtime change needs an explicit case- // above.- if (isSearchParamOnlyNavigation({ currentUrl, nextUrl, formMethod })) {- return false;+ // Only a mutation can change what the shell returns, so a GET re-runs it+ // only once the data has aged out — that covers out-of-band changes.+ if (!formMethod || formMethod === "GET") {+ return Date.now() - shellLoadedAt > SHELL_MAX_AGE_MS;}return defaultShouldRevalidate;@@ -166,6 +162,32 @@ export async function loader({ request }: LoaderFunctionArgs) {? getItarCertificationStatus(client, companyId, userId): Promise.resolve({ entityCertified: true, userCertified: true });+ // Streamed, not awaited. Each catches: the loader can exit early with+ // nothing awaiting them.+ const implementation = Promise.all([+ implementationHubPromise,+ getImplementationCheckStates(client, companyId),+ implementationSignalsPromise+ ])+ .then(([hub, checkStates, signals]) => ({+ implementationHub: hub.data ?? null,+ implementationCheckStates: checkStates.data ?? [],+ implementationSignals: signals+ }))+ .catch((error) => {+ log.error("Failed to load implementation hub", { companyId, error });+ return {+ implementationHub: null,+ implementationCheckStates: [],+ implementationSignals: null+ };+ });+ const auditLogEnabled = isAuditLogEnabled(client, companyId).catch(+ () => false+ );+ // Whether this user dismissed it is a user flag, read client-side.+ const changelog = getCachedChangelogPanelEntry().catch(() => null);+// Parallelize all requestsconst [companies,@@ -180,14 +202,9 @@ export async function loader({ request }: LoaderFunctionArgs) {claims,groups,defaults,- auditLogEnabled,modulePreferences,printerRoutes,- implementationHub,- implementationCheckStates,- implementationSignals,- itarCertification,- changelog+ itarCertification] = await Promise.all([getCompanies(client, userId),getEmployeeCompanies(client, userId),@@ -201,15 +218,9 @@ export async function loader({ request }: LoaderFunctionArgs) {getUserClaims(userId, companyId),getUserGroups(client, userId),getUserDefaults(client, userId, companyId),- isAuditLogEnabled(client, companyId).catch(() => false),getModulePreferences(client, userId, companyId),getPrinterRoutes(client, companyId),- implementationHubPromise,- getImplementationCheckStates(client, companyId),- implementationSignalsPromise,- itarCertificationPromise,- // Whether this user dismissed it is a user flag, read client-side.- getChangelogPanelEntry(getCarbonServiceRole()).catch(() => null)+ itarCertificationPromise]);// Empty groups is a valid pre-onboarding state (a first-run user with no@@ -325,9 +336,7 @@ export async function loader({ request }: LoaderFunctionArgs) {modulePreferences: modulePreferences.data ?? [],savedViews: savedViews.data ?? [],printerRoutes: printerRoutes.data ?? [],- implementationHub: implementationHub.data ?? null,- implementationCheckStates: implementationCheckStates.data ?? [],- implementationSignals,+ implementation,changelog,itarCertification: {...itarCertification,@@ -359,6 +368,7 @@ export async function loader({ request }: LoaderFunctionArgs) {}export default function AuthenticatedRoute() {+ const loaderData = useLoaderData<typeof loader>();const {company,session,@@ -369,7 +379,11 @@ export default function AuthenticatedRoute() {itarCertification,mfaEnrollment,sessionTimeout- } = useLoaderData<typeof loader>();+ } = loaderData;+ // biome-ignore lint/correctness/useExhaustiveDependencies: runs each time the loader does+ useEffect(() => {+ shellLoadedAt = Date.now();+ }, [loaderData]);const navigate = useNavigate();const permissions = usePermissions();const { isOpen, training, dismiss } = useTrainingPanel();diff --git a/apps/erp/app/routes/x+/accounting+/_layout.tsx b/apps/erp/app/routes/x+/accounting+/_layout.tsxindex 6403f19abb..7c5ed807fa 100644--- a/apps/erp/app/routes/x+/accounting+/_layout.tsx+++ b/apps/erp/app/routes/x+/accounting+/_layout.tsx@@ -7,8 +7,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { getIntegrationIdsByRole } from "@carbon/ee";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect } from "react-router";import { GroupedContentSidebar } from "~/components/Layout";import { CollapsibleSidebarProvider } from "~/components/Layout/Navigation";@@ -32,6 +37,9 @@ export const handle: Handle = {module: "accounting"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, companyGroupId } = await requirePermissions(request,diff --git a/apps/erp/app/routes/x+/accounting+/asset-class.$assetClassId.tsx b/apps/erp/app/routes/x+/accounting+/asset-class.$assetClassId.tsxindex a3a69cdc62..05ba67ab82 100644--- a/apps/erp/app/routes/x+/accounting+/asset-class.$assetClassId.tsx+++ b/apps/erp/app/routes/x+/accounting+/asset-class.$assetClassId.tsx@@ -6,7 +6,12 @@ import { assertIsPost, error, notFound, success } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData, useNavigate } from "react-router";import {fixedAssetClassValidator,@@ -17,6 +22,11 @@ import { AssetClassForm } from "~/modules/accounting/ui/FixedAssets";import { getCompanySettings } from "~/modules/settings";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["assetClassId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting"diff --git a/apps/erp/app/routes/x+/accounting+/asset-classes.tsx b/apps/erp/app/routes/x+/accounting+/asset-classes.tsxindex 297f01ecf1..8f9ec41b7f 100644--- a/apps/erp/app/routes/x+/accounting+/asset-classes.tsx+++ b/apps/erp/app/routes/x+/accounting+/asset-classes.tsx@@ -4,9 +4,13 @@import { requirePermissions } from "@carbon/auth/auth.server";import { Button, VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { LuCirclePlus } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData, useNavigate } from "react-router";import { usePermissions } from "~/hooks";import { getFixedAssetClasses } from "~/modules/accounting";@@ -21,6 +25,11 @@ export const handle: Handle = {to: path.to.assetClasses};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/cost-centers.tsx b/apps/erp/app/routes/x+/accounting+/cost-centers.tsxindex 9de9c5e6ab..8b43ff7f3f 100644--- a/apps/erp/app/routes/x+/accounting+/cost-centers.tsx+++ b/apps/erp/app/routes/x+/accounting+/cost-centers.tsx@@ -14,10 +14,14 @@ import {TabsList,TabsTrigger} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { useLingui } from "@lingui/react/macro";import { useCallback } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData, useNavigate } from "react-router";import { New } from "~/components";import { getCostCentersTree } from "~/modules/accounting";@@ -33,6 +37,9 @@ export const handle: Handle = {to: path.to.costCenters};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/depreciation-runs.tsx b/apps/erp/app/routes/x+/accounting+/depreciation-runs.tsxindex aa93023616..7a0258895c 100644--- a/apps/erp/app/routes/x+/accounting+/depreciation-runs.tsx+++ b/apps/erp/app/routes/x+/accounting+/depreciation-runs.tsx@@ -12,10 +12,13 @@ import {useDisclosure,VStack} from "@carbon/react";-import { formatDate } from "@carbon/utils";+import { formatDate, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { LuCirclePlus } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { useLoaderData, useNavigate } from "react-router";import { Confirm } from "~/components/Modals";import { usePermissions } from "~/hooks";@@ -31,6 +34,11 @@ export const handle: Handle = {to: path.to.depreciationRuns};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/dimensions.tsx b/apps/erp/app/routes/x+/accounting+/dimensions.tsxindex 28367b7089..817a10344d 100644--- a/apps/erp/app/routes/x+/accounting+/dimensions.tsx+++ b/apps/erp/app/routes/x+/accounting+/dimensions.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getDimensions } from "~/modules/accounting";import { DimensionsTable } from "~/modules/accounting/ui/Dimensions";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.dimensions};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyGroupId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/exchange-rates.tsx b/apps/erp/app/routes/x+/accounting+/exchange-rates.tsxindex 1ba0cc24ea..3ecbb0e6f8 100644--- a/apps/erp/app/routes/x+/accounting+/exchange-rates.tsx+++ b/apps/erp/app/routes/x+/accounting+/exchange-rates.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getCurrencies, getExchangeRates } from "~/modules/accounting";import { ExchangeRatesTable } from "~/modules/accounting/ui/ExchangeRates";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.exchangeRates};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, companyGroupId } = await requirePermissions(request,diff --git a/apps/erp/app/routes/x+/accounting+/fixed-assets.tsx b/apps/erp/app/routes/x+/accounting+/fixed-assets.tsxindex 80905c1830..444c918e31 100644--- a/apps/erp/app/routes/x+/accounting+/fixed-assets.tsx+++ b/apps/erp/app/routes/x+/accounting+/fixed-assets.tsx@@ -4,9 +4,13 @@import { requirePermissions } from "@carbon/auth/auth.server";import { Button, VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { LuCirclePlus } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData, useNavigate } from "react-router";import { usePermissions } from "~/hooks";import { getFixedAssetClassesList, getFixedAssets } from "~/modules/accounting";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.fixedAssets};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/intercompany.tsx b/apps/erp/app/routes/x+/accounting+/intercompany.tsxindex 4f526f8375..d9346f7b25 100644--- a/apps/erp/app/routes/x+/accounting+/intercompany.tsx+++ b/apps/erp/app/routes/x+/accounting+/intercompany.tsx@@ -4,9 +4,13 @@import { requirePermissions } from "@carbon/auth/auth.server";import { Button, VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { useLingui } from "@lingui/react/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useFetcher, useLoaderData } from "react-router";import { New } from "~/components";import { usePermissions, useUrlParams } from "~/hooks";@@ -21,6 +25,11 @@ export const handle: Handle = {to: path.to.intercompany};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyGroupId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/journals.tsx b/apps/erp/app/routes/x+/accounting+/journals.tsxindex 418d4d5f02..8b812dc908 100644--- a/apps/erp/app/routes/x+/accounting+/journals.tsx+++ b/apps/erp/app/routes/x+/accounting+/journals.tsx@@ -4,9 +4,13 @@import { requirePermissions } from "@carbon/auth/auth.server";import { Button, VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { LuCirclePlus } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useFetcher, useLoaderData } from "react-router";import { usePermissions } from "~/hooks";import { getJournalEntries } from "~/modules/accounting";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.accountingJournals};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/payment-terms.tsx b/apps/erp/app/routes/x+/accounting+/payment-terms.tsxindex e77be9533c..f998b3fb1e 100644--- a/apps/erp/app/routes/x+/accounting+/payment-terms.tsx+++ b/apps/erp/app/routes/x+/accounting+/payment-terms.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getPaymentTerms } from "~/modules/accounting";import { PaymentTermsTable } from "~/modules/accounting/ui/PaymentTerms";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.paymentTerms};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/periods.tsx b/apps/erp/app/routes/x+/accounting+/periods.tsxindex aff762b418..436894f92c 100644--- a/apps/erp/app/routes/x+/accounting+/periods.tsx+++ b/apps/erp/app/routes/x+/accounting+/periods.tsx@@ -6,10 +6,14 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { Button, VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans } from "@lingui/react/macro";import { LuCalendarPlus } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData, useNavigate } from "react-router";import { usePermissions } from "~/hooks";import { getAccountingPeriods } from "~/modules/accounting";@@ -22,6 +26,9 @@ export const handle: Handle = {to: path.to.accountingPeriods};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/projects.tsx b/apps/erp/app/routes/x+/accounting+/projects.tsxindex c60926c326..961e6b2fa7 100644--- a/apps/erp/app/routes/x+/accounting+/projects.tsx+++ b/apps/erp/app/routes/x+/accounting+/projects.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, Outlet, useLoaderData } from "react-router";import { getProjects } from "~/modules/accounting";import { ProjectsTable } from "~/modules/accounting/ui/Projects";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.projects};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/accounting+/sync-tieout.tsx b/apps/erp/app/routes/x+/accounting+/sync-tieout.tsxindex 6a6d993fae..03f3ba472f 100644--- a/apps/erp/app/routes/x+/accounting+/sync-tieout.tsx+++ b/apps/erp/app/routes/x+/accounting+/sync-tieout.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { useRouteData } from "~/hooks";import { getAccountingSyncTieOut } from "~/modules/accounting";@@ -30,6 +34,11 @@ function filterValues(return match.operator === "in" ? match.value.split(",") : [match.value];}+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting",diff --git a/apps/erp/app/routes/x+/assembly+/$id.tsx b/apps/erp/app/routes/x+/assembly+/$id.tsxindex f20d216dd3..361419cf31 100644--- a/apps/erp/app/routes/x+/assembly+/$id.tsx+++ b/apps/erp/app/routes/x+/assembly+/$id.tsx@@ -14,6 +14,7 @@ import {useInterval,useMode} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import type {AssemblyGraph,AssemblyPlayerHandle,@@ -27,7 +28,11 @@ import {} from "@carbon/viewer";import { msg } from "@lingui/core/macro";import { useCallback, useEffect, useMemo, useRef, useState } from "react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {data,redirect,@@ -72,6 +77,11 @@ export const handle: Handle = {module: "production"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/assembly+/_layout.tsx b/apps/erp/app/routes/x+/assembly+/_layout.tsxindex 0d731661f8..835233115a 100644--- a/apps/erp/app/routes/x+/assembly+/_layout.tsx+++ b/apps/erp/app/routes/x+/assembly+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -13,6 +18,9 @@ export const meta: MetaFunction = () => {return [{ title: "Carbon | Assembly" }];};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {view: "production"diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.$supplierPartId.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.$supplierPartId.tsxindex cd0f77cba0..57b30682c5 100644--- a/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.$supplierPartId.tsx+++ b/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.$supplierPartId.tsx@@ -7,7 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { useRouteData } from "@carbon/react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData, useNavigate, useParams } from "react-router";import type { ConsumableSummary } from "~/modules/items";import { supplierPartValidator, upsertSupplierPart } from "~/modules/items";@@ -16,6 +21,11 @@ import { getDatabaseClient } from "~/services/database.server";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId", "supplierPartId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.tsxindex 6eeab686d9..52b5bb55c5 100644--- a/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.tsx+++ b/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.tsx@@ -7,8 +7,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { Suspense } from "react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Await, redirect, useLoaderData, useParams } from "react-router";import { useRouteData } from "~/hooks";import { getBatchProperties } from "~/modules/inventory";@@ -22,6 +27,11 @@ import {import { ItemPurchasingForm, SupplierParts } from "~/modules/items/ui/Item";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.tsxindex 7fa5cd310d..88576b34d8 100644--- a/apps/erp/app/routes/x+/consumable+/$itemId.tsx+++ b/apps/erp/app/routes/x+/consumable+/$itemId.tsx@@ -6,9 +6,13 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { useRouteData } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Suspense } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Await,Outlet,@@ -45,6 +49,11 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/consumable+/_layout.tsx b/apps/erp/app/routes/x+/consumable+/_layout.tsxindex 58fecaee14..fb75c36549 100644--- a/apps/erp/app/routes/x+/consumable+/_layout.tsx+++ b/apps/erp/app/routes/x+/consumable+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import { getUnitOfMeasuresList } from "~/modules/items";import { getLocationsList } from "~/modules/resources";@@ -21,6 +26,9 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/credits+/$memoId.tsx b/apps/erp/app/routes/x+/credits+/$memoId.tsxindex 5d6cd67b7a..11af98ab06 100644--- a/apps/erp/app/routes/x+/credits+/$memoId.tsx+++ b/apps/erp/app/routes/x+/credits+/$memoId.tsx@@ -7,8 +7,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, redirect, useLoaderData } from "react-router";import {getMemo,@@ -46,6 +51,11 @@ export const handle: Handle = {// it to invoices happens on the payment/receipt screen (alongside cash), so the// settlement UI lives in one place. The invoice's "Applied" panel shows where a// posted credit ended up.+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["memoId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "invoicing"diff --git a/apps/erp/app/routes/x+/customer+/$customerId.bank-accounts.tsx b/apps/erp/app/routes/x+/customer+/$customerId.bank-accounts.tsxindex cebe81fba2..21ab37436e 100644--- a/apps/erp/app/routes/x+/customer+/$customerId.bank-accounts.tsx+++ b/apps/erp/app/routes/x+/customer+/$customerId.bank-accounts.tsx@@ -5,12 +5,21 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData } from "react-router";import { getCustomerBankAccounts } from "~/modules/sales";import CustomerBankAccounts from "~/modules/sales/ui/Customer/CustomerBankAccounts";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["customerId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "accounting"diff --git a/apps/erp/app/routes/x+/customer+/$customerId.contacts.tsx b/apps/erp/app/routes/x+/customer+/$customerId.contacts.tsxindex a6aa9c90bb..69e1b9dd1f 100644--- a/apps/erp/app/routes/x+/customer+/$customerId.contacts.tsx+++ b/apps/erp/app/routes/x+/customer+/$customerId.contacts.tsx@@ -5,12 +5,21 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData } from "react-router";import { getCustomerContacts } from "~/modules/sales";import { CustomerContacts } from "~/modules/sales/ui/Customer";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["customerId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "sales"diff --git a/apps/erp/app/routes/x+/customer+/$customerId.locations.tsx b/apps/erp/app/routes/x+/customer+/$customerId.locations.tsxindex 56ba9dbca7..e395e4afb0 100644--- a/apps/erp/app/routes/x+/customer+/$customerId.locations.tsx+++ b/apps/erp/app/routes/x+/customer+/$customerId.locations.tsx@@ -5,12 +5,21 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData } from "react-router";import { getCustomerLocations } from "~/modules/sales";import { CustomerLocations } from "~/modules/sales/ui/Customer";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["customerId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "sales"diff --git a/apps/erp/app/routes/x+/customer+/$customerId.tsx b/apps/erp/app/routes/x+/customer+/$customerId.tsxindex 29cdd8c92f..37fbff9565 100644--- a/apps/erp/app/routes/x+/customer+/$customerId.tsx+++ b/apps/erp/app/routes/x+/customer+/$customerId.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { cn } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect } from "react-router";import { usePermissions } from "~/hooks";import {@@ -29,6 +33,11 @@ export const handle: Handle = {module: "sales"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["customerId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales"diff --git a/apps/erp/app/routes/x+/customer+/_layout.tsx b/apps/erp/app/routes/x+/customer+/_layout.tsxindex 613a534e93..09b091bc84 100644--- a/apps/erp/app/routes/x+/customer+/_layout.tsx+++ b/apps/erp/app/routes/x+/customer+/_layout.tsx@@ -4,8 +4,13 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import { getCustomerStatuses, getCustomerTypes } from "~/modules/sales";import type { Handle } from "~/utils/handle";@@ -21,6 +26,9 @@ export const handle: Handle = {module: "sales"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales"diff --git a/apps/erp/app/routes/x+/depreciation-run+/$depreciationRunId.tsx b/apps/erp/app/routes/x+/depreciation-run+/$depreciationRunId.tsxindex 0a39dae412..a6fc68fdac 100644--- a/apps/erp/app/routes/x+/depreciation-run+/$depreciationRunId.tsx+++ b/apps/erp/app/routes/x+/depreciation-run+/$depreciationRunId.tsx@@ -21,10 +21,13 @@ import {IconButton,useDisclosure} from "@carbon/react";-import { formatDate } from "@carbon/utils";+import { formatDate, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { LuEllipsisVertical, LuRepeat, LuTrash } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Link,Outlet,@@ -55,6 +58,11 @@ export const handle: Handle = {module: "accounting"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["depreciationRunId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "accounting"diff --git a/apps/erp/app/routes/x+/documents+/search.tsx b/apps/erp/app/routes/x+/documents+/search.tsxindex da70277cc4..3573606dc4 100644--- a/apps/erp/app/routes/x+/documents+/search.tsx+++ b/apps/erp/app/routes/x+/documents+/search.tsx@@ -7,7 +7,11 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { generateDownloadToken } from "@carbon/auth/download-token.server";import { flash } from "@carbon/auth/session.server";import { ResizablePanel, ResizablePanelGroup, VStack } from "@carbon/react";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import type { Document } from "~/modules/documents";import {@@ -19,6 +23,11 @@ import {import { path } from "~/utils/path";import { getGenericQueryFilters } from "~/utils/query";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "documents"diff --git a/apps/erp/app/routes/x+/fixed-asset+/$fixedAssetId.tsx b/apps/erp/app/routes/x+/fixed-asset+/$fixedAssetId.tsxindex 82e11c5dd4..5a96ea7ead 100644--- a/apps/erp/app/routes/x+/fixed-asset+/$fixedAssetId.tsx+++ b/apps/erp/app/routes/x+/fixed-asset+/$fixedAssetId.tsx@@ -22,6 +22,7 @@ import {DropdownMenuTrigger,useDisclosure} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import {LuChevronDown,@@ -33,7 +34,10 @@ import {LuStore,LuTrash} from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Link,Outlet,@@ -69,6 +73,11 @@ export const handle: Handle = {module: "accounting"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["fixedAssetId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "accounting"diff --git a/apps/erp/app/routes/x+/get-started+/_layout.tsx b/apps/erp/app/routes/x+/get-started+/_layout.tsxindex 77c449416c..8f1603af06 100644--- a/apps/erp/app/routes/x+/get-started+/_layout.tsx+++ b/apps/erp/app/routes/x+/get-started+/_layout.tsx@@ -27,9 +27,14 @@ import {HubProvider,toFormFields} from "@carbon/onboarding/ui";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { useCallback, useEffect, useMemo, useRef } from "react";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import {Outlet,redirect,@@ -133,6 +138,9 @@ export const handle: Handle = {to: path.to.getStarted};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});diff --git a/apps/erp/app/routes/x+/inspection+/$id.tsx b/apps/erp/app/routes/x+/inspection+/$id.tsxindex 1cdd57b1ed..0ebcfa274d 100644--- a/apps/erp/app/routes/x+/inspection+/$id.tsx+++ b/apps/erp/app/routes/x+/inspection+/$id.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, redirect, useLoaderData } from "react-router";import invariant from "tiny-invariant";import {@@ -46,6 +50,11 @@ export const handle: Handle = {module: "quality"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/inspection+/_layout.tsx b/apps/erp/app/routes/x+/inspection+/_layout.tsxindex a71a23ba75..299922e950 100644--- a/apps/erp/app/routes/x+/inspection+/_layout.tsx+++ b/apps/erp/app/routes/x+/inspection+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -13,6 +18,9 @@ export const meta: MetaFunction = () => {return [{ title: "Carbon | Inspection" }];};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {view: "quality"diff --git a/apps/erp/app/routes/x+/inventory+/_layout.tsx b/apps/erp/app/routes/x+/inventory+/_layout.tsxindex fcd763040a..663e32d7a2 100644--- a/apps/erp/app/routes/x+/inventory+/_layout.tsx+++ b/apps/erp/app/routes/x+/inventory+/_layout.tsx@@ -4,8 +4,13 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import { GroupedContentSidebar } from "~/components/Layout";import { CollapsibleSidebarProvider } from "~/components/Layout/Navigation";@@ -25,6 +30,9 @@ export const handle: Handle = {module: "inventory"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/inventory+/inventory-count.tsx b/apps/erp/app/routes/x+/inventory+/inventory-count.tsxindex b89e1061db..0c584d4ce4 100644--- a/apps/erp/app/routes/x+/inventory+/inventory-count.tsx+++ b/apps/erp/app/routes/x+/inventory+/inventory-count.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getInventoryCounts, InventoryCountsTable } from "~/modules/inventory";import { getLocationsList } from "~/modules/resources";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.inventoryCounts};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/inventory+/kanbans.tsx b/apps/erp/app/routes/x+/inventory+/kanbans.tsxindex 1b63aaff5f..0a1d7d9e15 100644--- a/apps/erp/app/routes/x+/inventory+/kanbans.tsx+++ b/apps/erp/app/routes/x+/inventory+/kanbans.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getKanbans } from "~/modules/inventory";import KanbansTable from "~/modules/inventory/ui/Kanbans/KanbansTable";@@ -24,6 +28,11 @@ export const handle: Handle = {module: "inventory"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "inventory",diff --git a/apps/erp/app/routes/x+/inventory+/quantities+/$itemId.tsx b/apps/erp/app/routes/x+/inventory+/quantities+/$itemId.tsxindex 01e99b96d5..343c329a3a 100644--- a/apps/erp/app/routes/x+/inventory+/quantities+/$itemId.tsx+++ b/apps/erp/app/routes/x+/inventory+/quantities+/$itemId.tsx@@ -11,13 +11,22 @@ import {ScrollArea,VStack} from "@carbon/react";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import InventoryItemHeader from "~/modules/inventory/ui/Inventory/InventoryItemHeader";import { getItem, getPickMethod, upsertPickMethod } from "~/modules/items";import { resolveLocationId } from "~/modules/shared/location.server";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"], search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/inventory+/quantities.tsx b/apps/erp/app/routes/x+/inventory+/quantities.tsxindex e9f5df6856..ac0634efee 100644--- a/apps/erp/app/routes/x+/inventory+/quantities.tsx+++ b/apps/erp/app/routes/x+/inventory+/quantities.tsx@@ -6,8 +6,11 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { ResizablePanel, ResizablePanelGroup, VStack } from "@carbon/react";-import { pluckUnique } from "@carbon/utils";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation, pluckUnique } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import type { InventoryItem } from "~/modules/inventory";import {@@ -27,6 +30,11 @@ import { getUserDefaults } from "~/modules/users/users.server";import { path } from "~/utils/path";import { getGenericQueryFilters } from "~/utils/query";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "inventory",diff --git a/apps/erp/app/routes/x+/inventory+/shipping-methods.tsx b/apps/erp/app/routes/x+/inventory+/shipping-methods.tsxindex 76eae10583..a043ef913a 100644--- a/apps/erp/app/routes/x+/inventory+/shipping-methods.tsx+++ b/apps/erp/app/routes/x+/inventory+/shipping-methods.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getAccountsList } from "~/modules/accounting";import { getShippingMethods, ShippingMethodsTable } from "~/modules/inventory";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.shippingMethods};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, companyGroupId } = await requirePermissions(request,diff --git a/apps/erp/app/routes/x+/inventory+/stock-movements.tsx b/apps/erp/app/routes/x+/inventory+/stock-movements.tsxindex 49f58b09b1..b4c7a9cf95 100644--- a/apps/erp/app/routes/x+/inventory+/stock-movements.tsx+++ b/apps/erp/app/routes/x+/inventory+/stock-movements.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData } from "react-router";import { getStockMovements } from "~/modules/inventory";import StockMovementsTable from "~/modules/inventory/ui/StockMovements/StockMovementsTable";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.stockMovements};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/inventory+/storage-rules.$id.tsx b/apps/erp/app/routes/x+/inventory+/storage-rules.$id.tsxindex 06f21a86b5..5558460644 100644--- a/apps/erp/app/routes/x+/inventory+/storage-rules.$id.tsx+++ b/apps/erp/app/routes/x+/inventory+/storage-rules.$id.tsx@@ -9,13 +9,23 @@ import { requireFeature } from "@carbon/ee/plan.server";import { upsertEnforcementRule } from "@carbon/ee/rules.server";import { validationError, validator } from "@carbon/form";import type { ConditionAst } from "@carbon/utils";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, redirect, useLoaderData, useNavigate } from "react-router";import { storageRuleValidator } from "~/modules/inventory";import StorageRuleForm from "~/modules/inventory/ui/StorageRules/StorageRuleForm";import { getEnforcementRule } from "~/modules/shared";import { getParams, path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/inventory+/storage-rules.tsx b/apps/erp/app/routes/x+/inventory+/storage-rules.tsxindex 0ac08dc38c..b6285dbf59 100644--- a/apps/erp/app/routes/x+/inventory+/storage-rules.tsx+++ b/apps/erp/app/routes/x+/inventory+/storage-rules.tsx@@ -5,8 +5,12 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import StorageRulesGroups from "~/modules/inventory/ui/StorageRules/StorageRulesGroups";@@ -23,6 +27,9 @@ export const handle: Handle = {to: path.to.storageRules};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "inventory",diff --git a/apps/erp/app/routes/x+/inventory+/storage-types.tsx b/apps/erp/app/routes/x+/inventory+/storage-types.tsxindex f6259ff208..111b5f6fe2 100644--- a/apps/erp/app/routes/x+/inventory+/storage-types.tsx+++ b/apps/erp/app/routes/x+/inventory+/storage-types.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getStorageTypes } from "~/modules/inventory";import StorageTypesTable from "~/modules/inventory/ui/StorageTypes/StorageTypesTable";@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.storageTypes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/inventory+/storage-units.tsx b/apps/erp/app/routes/x+/inventory+/storage-units.tsxindex c81ec65779..7cfe4cee9a 100644--- a/apps/erp/app/routes/x+/inventory+/storage-units.tsx+++ b/apps/erp/app/routes/x+/inventory+/storage-units.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import {getStorageTypesList,@@ -33,6 +37,11 @@ export const handle: Handle = {// Nodes below this still render with an expand chevron and lazy-load on click.const EAGER_EXPAND_MAX_DEPTH = 5;+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "inventory",diff --git a/apps/erp/app/routes/x+/inventory-count+/$id.tsx b/apps/erp/app/routes/x+/inventory-count+/$id.tsxindex 3527009cfe..460a34ac94 100644--- a/apps/erp/app/routes/x+/inventory-count+/$id.tsx+++ b/apps/erp/app/routes/x+/inventory-count+/$id.tsx@@ -5,9 +5,12 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import { pluckUnique } from "@carbon/utils";+import { isUnaffectedByNavigation, pluckUnique } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import {getInventoryCount,@@ -35,6 +38,11 @@ export const handle: Handle = {module: "inventory"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"], search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/invoicing+/_layout.tsx b/apps/erp/app/routes/x+/invoicing+/_layout.tsxindex e515067ce5..777314c593 100644--- a/apps/erp/app/routes/x+/invoicing+/_layout.tsx+++ b/apps/erp/app/routes/x+/invoicing+/_layout.tsx@@ -4,8 +4,13 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import { GroupedContentSidebar } from "~/components/Layout";import { CollapsibleSidebarProvider } from "~/components/Layout/Navigation";@@ -23,6 +28,9 @@ export const handle: Handle = {module: "invoicing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {view: "invoicing"diff --git a/apps/erp/app/routes/x+/invoicing+/charges.$id.tsx b/apps/erp/app/routes/x+/invoicing+/charges.$id.tsxindex 0d537cc5f2..0e58dea760 100644--- a/apps/erp/app/routes/x+/invoicing+/charges.$id.tsx+++ b/apps/erp/app/routes/x+/invoicing+/charges.$id.tsx@@ -23,10 +23,13 @@ import {useDisclosure,VStack} from "@carbon/react";-import { formatDate } from "@carbon/utils";+import { formatDate, isUnaffectedByNavigation } from "@carbon/utils";import { Trans, useLingui } from "@lingui/react/macro";import { useLocale } from "@react-aria/i18n";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData, useNavigate } from "react-router";import { Hyperlink } from "~/components";import { Enumerable } from "~/components/Enumerable";@@ -35,6 +38,11 @@ import { useCurrencyFormatter, usePermissions } from "~/hooks";import { ChargeStatus, getCharge } from "~/modules/invoicing";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, companyGroupId } = await requirePermissions(request,diff --git a/apps/erp/app/routes/x+/invoicing+/charges.tsx b/apps/erp/app/routes/x+/invoicing+/charges.tsxindex 369ecaf5b9..0841821580 100644--- a/apps/erp/app/routes/x+/invoicing+/charges.tsx+++ b/apps/erp/app/routes/x+/invoicing+/charges.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { ChargesTable, getCharges } from "~/modules/invoicing";import type { Handle } from "~/utils/handle";@@ -20,6 +24,11 @@ export const handle: Handle = {module: "invoicing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "invoicing"diff --git a/apps/erp/app/routes/x+/invoicing+/payables.tsx b/apps/erp/app/routes/x+/invoicing+/payables.tsxindex df9f6b850b..4a28b0cd99 100644--- a/apps/erp/app/routes/x+/invoicing+/payables.tsx+++ b/apps/erp/app/routes/x+/invoicing+/payables.tsx@@ -3,9 +3,12 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";-import { datetime } from "@carbon/utils";+import { datetime, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { useLoaderData } from "react-router";import {ARAPWorkbench,@@ -32,6 +35,11 @@ function parseBuckets(raw: string | null): [number, number, number] {return [30, 60, 90];}+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "invoicing"diff --git a/apps/erp/app/routes/x+/invoicing+/receivables.tsx b/apps/erp/app/routes/x+/invoicing+/receivables.tsxindex 41bd7a62b0..c8365bae7e 100644--- a/apps/erp/app/routes/x+/invoicing+/receivables.tsx+++ b/apps/erp/app/routes/x+/invoicing+/receivables.tsx@@ -3,9 +3,12 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";-import { datetime } from "@carbon/utils";+import { datetime, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { useLoaderData } from "react-router";import {ARAPWorkbench,@@ -32,6 +35,11 @@ function parseBuckets(raw: string | null): [number, number, number] {return [30, 60, 90];}+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "invoicing"diff --git a/apps/erp/app/routes/x+/issue+/$id.tsx b/apps/erp/app/routes/x+/issue+/$id.tsxindex 96807f2f5e..c651d6b4c4 100644--- a/apps/erp/app/routes/x+/issue+/$id.tsx+++ b/apps/erp/app/routes/x+/issue+/$id.tsx@@ -7,10 +7,14 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { useLingui } from "@lingui/react/macro";import { Suspense } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Await,Outlet,@@ -51,6 +55,11 @@ export const handle: Handle = {module: "quality"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/items+/change-notice+/$id.$affectedId.details.$supplierPartId.tsx b/apps/erp/app/routes/x+/items+/change-notice+/$id.$affectedId.details.$supplierPartId.tsxindex 2086ce4991..b6a0a3fd8b 100644--- a/apps/erp/app/routes/x+/items+/change-notice+/$id.$affectedId.details.$supplierPartId.tsx+++ b/apps/erp/app/routes/x+/items+/change-notice+/$id.$affectedId.details.$supplierPartId.tsx@@ -3,7 +3,11 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { useLoaderData, useNavigate, useParams } from "react-router";import { useRouteData } from "~/hooks";import type { AffectedItemDraft } from "~/modules/items/ui/ChangeNotice";@@ -17,6 +21,13 @@ import { path } from "~/utils/path";// MUST be seeded or saving would wipe them) + purchase history. No action here:// the form posts to the part edit action (path.to.partSupplier), which returns// { success } so the CO stays put.+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, {+ params: ["affectedId", "id", "supplierPartId"]+ })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/items+/change-notice+/$id.tsx b/apps/erp/app/routes/x+/items+/change-notice+/$id.tsxindex 653177a238..e3067bf7de 100644--- a/apps/erp/app/routes/x+/items+/change-notice+/$id.tsx+++ b/apps/erp/app/routes/x+/items+/change-notice+/$id.tsx@@ -5,9 +5,14 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";+import { getLogger } from "@carbon/logger";import type { JSONContent } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import {@@ -44,6 +49,8 @@ import { getTagsList } from "~/modules/shared";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";+const logger = getLogger("erp", "change-notice");+export const handle: Handle = {// Leaf crumb: show the CO's readable number (from loader data), not a second// static "Change Notices" (the parent _layout already renders the list crumb).@@ -57,6 +64,11 @@ export const handle: Handle = {hideModuleSidebar: true};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"@@ -65,23 +77,35 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { id } = params;if (!id) throw new Error("Could not find id");- const [changeNotice, types, affected, diff, actions, nonConformances] =- await Promise.all([- getChangeNotice(client, id, companyId),- getChangeNoticeTypesList(client, companyId),- getChangeNoticeAffectedItems(client, id, companyId),- getChangeNoticeDiff(client, id, companyId),- getChangeNoticeActions(client, id, companyId),- // NCR cross-link picker options (4a).- getIssues(client, companyId)- ]);-- // Company locations feed the embedded PartProperties pick-method editor.- const locations = (await getLocationsList(client, companyId)).data ?? [];+ const [+ changeNotice,+ types,+ affected,+ diff,+ actions,+ nonConformances,+ locationsList,+ requiredActionsList,+ partTags,+ operationTags+ ] = await Promise.all([+ getChangeNotice(client, id, companyId),+ getChangeNoticeTypesList(client, companyId),+ getChangeNoticeAffectedItems(client, id, companyId),+ getChangeNoticeDiff(client, id, companyId),+ getChangeNoticeActions(client, id, companyId),+ // NCR cross-link picker options (4a).+ getIssues(client, companyId),+ // Company locations feed the embedded PartProperties pick-method editor.+ getLocationsList(client, companyId),+ // Active default-action templates for the "Add Actions" picker.+ getChangeNoticeRequiredActionsList(client, companyId),+ getTagsList(client, companyId, "part"),+ getTagsList(client, companyId, "operation")+ ]);- // Active default-action templates for the "Add Actions" picker.- const requiredActions =- (await getChangeNoticeRequiredActionsList(client, companyId)).data ?? [];+ const locations = locationsList.data ?? [];+ const requiredActions = requiredActionsList.data ?? [];if (changeNotice.error) {throw redirect(@@ -96,23 +120,31 @@ export async function loader({ request, params }: LoaderFunctionArgs) {// Human label for the currently-linked NCR (so the sidebar link shows the// readable id/name, not the raw id).const linkedNonConformanceId = changeNotice.data?.nonConformanceId ?? null;- const linkedNonConformance = linkedNonConformanceId- ? (await getIssue(client, linkedNonConformanceId)).data+ const linkedNonConformancePromise = linkedNonConformanceId+ ? getIssue(client, linkedNonConformanceId).then((issue) => issue.data): null;const affectedRows = affected.data ?? [];// Impact = where each affected item is used across the system (jobs, POs,// sales, receipts, methods, NCRs, …) — the same "Used In" data the part detail- // page loads, one entry per affected item.- const impactUsedIn = await Promise.all(+ // page loads, one entry per affected item. Streamed: only the impact panel+ // reads it.+ const impactUsedIn = Promise.all(affectedRows.map(async (a) => ({itemId: a.itemId,readableIdWithRevision: a.item?.readableIdWithRevision ?? a.itemId,itemName: a.item?.name ?? null,usedIn: await getPartUsedIn(client, a.itemId, companyId)}))- );+ ).catch((error) => {+ logger.error("Failed to load change notice impact", {+ companyId,+ changeNoticeId: id,+ error+ });+ return [];+ });const diffByAffectedId = new Map((diff.data?.items ?? []).map((entry) => [entry.affectedItemId, entry])@@ -154,56 +186,51 @@ export async function loader({ request, params }: LoaderFunctionArgs) {affectedItem.changeType === "Replacement Part" ||affectedItem.changeType === "New Part") &&affectedItem.item?.type === "Part";- let partData = null;- if (needsAttributes) {- const [partSummary, supplierParts, pickMethods, partTags] =- await Promise.all([+ const partDataPromise = needsAttributes+ ? Promise.all([getPart(client, draftItemId, companyId),getSupplierParts(client, draftItemId, companyId),- getPickMethods(client, draftItemId, companyId),- getTagsList(client, companyId, "part")- ]);- if (partSummary.data) {- partData = {- itemId: draftItemId,- locations,- partSummary: partSummary.data,- files: getItemFiles(client, draftItemId, companyId),- supplierParts: supplierParts.data ?? [],- pickMethods: pickMethods.data ?? [],- makeMethods: getMakeMethods(client, draftItemId, companyId),- tags: partTags.data ?? []- };- }- }+ getPickMethods(client, draftItemId, companyId)+ ]).then(([partSummary, supplierParts, pickMethods]) =>+ partSummary.data+ ? {+ itemId: draftItemId,+ locations,+ partSummary: partSummary.data,+ files: getItemFiles(client, draftItemId, companyId),+ supplierParts: supplierParts.data ?? [],+ pickMethods: pickMethods.data ?? [],+ makeMethods: getMakeMethods(client, draftItemId, companyId),+ tags: partTags.data ?? []+ }+ : null+ )+ : null;const [makeMethod,methodMaterials,methodOperations,- tags,manufacturing,- revisionLock+ revisionLock,+ partData] = await Promise.all([getMakeMethodById(client, draftMakeMethodId, companyId),getMethodMaterialsByMakeMethod(client, draftMakeMethodId),getMethodOperationsByMakeMethodId(client, draftMakeMethodId),- getTagsList(client, companyId, "operation"),getItemManufacturing(client, draftItemId, companyId),- getRevisionLock(client, { itemId: draftItemId, companyId })+ getRevisionLock(client, { itemId: draftItemId, companyId }),+ partDataPromise]);const config = manufacturing.data?.requiresConfiguration- ? {- parameters: (- await getConfigurationParameters(client, draftItemId, companyId)- ).parameters,- configurationRules: await getConfigurationRules(- client,- draftItemId,- companyId- )- }+ ? await Promise.all([+ getConfigurationParameters(client, draftItemId, companyId),+ getConfigurationRules(client, draftItemId, companyId)+ ]).then(([{ parameters }, configurationRules]) => ({+ parameters,+ configurationRules+ })): {parameters: [] as Awaited<ReturnType<typeof getConfigurationParameters>@@ -241,7 +268,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {workCenterId: operation.workCenterId ?? undefined,workInstruction: operation.workInstruction as JSONContent | null})) ?? [],- tags: tags.data ?? [],+ tags: operationTags.data ?? [],configurable: manufacturing.data?.requiresConfiguration ?? false,configurationRules: config.configurationRules,parameters: config.parameters,@@ -271,6 +298,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {: []);+ const linkedNonConformance = await linkedNonConformancePromise;+return {changeNotice: changeNotice.data,types: types.data ?? [],diff --git a/apps/erp/app/routes/x+/items+/change-notice-actions.tsx b/apps/erp/app/routes/x+/items+/change-notice-actions.tsxindex 8efa7a73aa..d5566b1bf7 100644--- a/apps/erp/app/routes/x+/items+/change-notice-actions.tsx+++ b/apps/erp/app/routes/x+/items+/change-notice-actions.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getChangeNoticeRequiredActions } from "~/modules/items";import { ChangeNoticeRequiredActionsTable } from "~/modules/items/ui/ChangeNoticeActions";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.changeNoticeRequiredActions};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/items+/change-notice-types.tsx b/apps/erp/app/routes/x+/items+/change-notice-types.tsxindex d84ce618ce..3af1f19943 100644--- a/apps/erp/app/routes/x+/items+/change-notice-types.tsx+++ b/apps/erp/app/routes/x+/items+/change-notice-types.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getChangeNoticeTypes } from "~/modules/items";import { ChangeNoticeTypesTable } from "~/modules/items/ui/ChangeNoticeTypes";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.changeNoticeTypes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/items+/dimensions.tsx b/apps/erp/app/routes/x+/items+/dimensions.tsxindex 63627bcc98..eb41430b19 100644--- a/apps/erp/app/routes/x+/items+/dimensions.tsx+++ b/apps/erp/app/routes/x+/items+/dimensions.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getMaterialDimensions } from "~/modules/items";import MaterialDimensionsTable from "~/modules/items/ui/MaterialDimensions/MaterialDimensionsTable";@@ -24,6 +28,11 @@ export const handle: Handle = {to: path.to.materialDimensions};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/items+/finishes.tsx b/apps/erp/app/routes/x+/items+/finishes.tsxindex 04979314a9..2f06ec47cd 100644--- a/apps/erp/app/routes/x+/items+/finishes.tsx+++ b/apps/erp/app/routes/x+/items+/finishes.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getMaterialFinishes } from "~/modules/items";import MaterialFinishesTable from "~/modules/items/ui/MaterialFinishes/MaterialFinishesTable";@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.materialFinishes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/items+/forms.tsx b/apps/erp/app/routes/x+/items+/forms.tsxindex a4367afa6c..137c67f81e 100644--- a/apps/erp/app/routes/x+/items+/forms.tsx+++ b/apps/erp/app/routes/x+/items+/forms.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getMaterialForms } from "~/modules/items";import { MaterialFormsTable } from "~/modules/items/ui/MaterialShapes";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.materialForms};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/items+/grades.tsx b/apps/erp/app/routes/x+/items+/grades.tsxindex e77e151e13..7672fa7d98 100644--- a/apps/erp/app/routes/x+/items+/grades.tsx+++ b/apps/erp/app/routes/x+/items+/grades.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getMaterialGrades } from "~/modules/items";import MaterialGradesTable from "~/modules/items/ui/MaterialGrades/MaterialGradesTable";@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.materialGrades};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/items+/groups.tsx b/apps/erp/app/routes/x+/items+/groups.tsxindex 42f58606c8..5456a45270 100644--- a/apps/erp/app/routes/x+/items+/groups.tsx+++ b/apps/erp/app/routes/x+/items+/groups.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getAccountsList } from "~/modules/accounting";import { getItemPostingGroups } from "~/modules/items";@@ -21,6 +25,11 @@ export const handle: Handle = {to: path.to.itemPostingGroups};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, companyGroupId } = await requirePermissions(request,diff --git a/apps/erp/app/routes/x+/items+/substances.tsx b/apps/erp/app/routes/x+/items+/substances.tsxindex 8dd1ec059c..d061a0492f 100644--- a/apps/erp/app/routes/x+/items+/substances.tsx+++ b/apps/erp/app/routes/x+/items+/substances.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getMaterialSubstances } from "~/modules/items";import { MaterialSubstancesTable } from "~/modules/items/ui/MaterialSubstances";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.materialSubstances};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/items+/types.tsx b/apps/erp/app/routes/x+/items+/types.tsxindex 4664607d69..9b3e67f2ce 100644--- a/apps/erp/app/routes/x+/items+/types.tsx+++ b/apps/erp/app/routes/x+/items+/types.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getMaterialTypes } from "~/modules/items";import MaterialTypesTable from "~/modules/items/ui/MaterialTypes/MaterialTypesTable";@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.materialTypes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/items+/uom.tsx b/apps/erp/app/routes/x+/items+/uom.tsxindex c08a29a90b..c4f80a4dcd 100644--- a/apps/erp/app/routes/x+/items+/uom.tsx+++ b/apps/erp/app/routes/x+/items+/uom.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getUnitOfMeasures } from "~/modules/items";import { UnitOfMeasuresTable } from "~/modules/items/ui/UnitOfMeasure";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.uoms};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/job+/$jobId.events.tsx b/apps/erp/app/routes/x+/job+/$jobId.events.tsxindex b6b7bf93c2..539875329b 100644--- a/apps/erp/app/routes/x+/job+/$jobId.events.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.events.tsx@@ -6,7 +6,11 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { useMount, VStack } from "@carbon/react";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { usePanels } from "~/components/Layout";import {@@ -18,6 +22,11 @@ import { getWorkCentersList } from "~/modules/resources";import { path, requestReferrer } from "~/utils/path";import { getGenericQueryFilters } from "~/utils/query";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["jobId"], search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production"diff --git a/apps/erp/app/routes/x+/job+/$jobId.quantities.tsx b/apps/erp/app/routes/x+/job+/$jobId.quantities.tsxindex aa5ac20a6d..0be26b54e0 100644--- a/apps/erp/app/routes/x+/job+/$jobId.quantities.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.quantities.tsx@@ -6,7 +6,11 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { useMount, VStack } from "@carbon/react";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { usePanels } from "~/components/Layout";import {@@ -18,6 +22,11 @@ import { ProductionQuantitiesTable } from "~/modules/production/ui/Jobs";import { path, requestReferrer } from "~/utils/path";import { getGenericQueryFilters } from "~/utils/query";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["jobId"], search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production"diff --git a/apps/erp/app/routes/x+/job+/$jobId.tsx b/apps/erp/app/routes/x+/job+/$jobId.tsxindex c695bfac11..a1fc63f5c5 100644--- a/apps/erp/app/routes/x+/job+/$jobId.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.tsx@@ -6,11 +6,14 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { activeJobStatuses } from "@carbon/database";-import { datetime } from "@carbon/utils";+import { datetime, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans } from "@lingui/react/macro";import { Suspense, useMemo } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Await,Outlet,@@ -82,6 +85,11 @@ export const handle: Handle = {module: "production"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["jobId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/job+/_layout.tsx b/apps/erp/app/routes/x+/job+/_layout.tsxindex f396d83788..c7c8f3358d 100644--- a/apps/erp/app/routes/x+/job+/_layout.tsx+++ b/apps/erp/app/routes/x+/job+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -19,6 +24,9 @@ export const handle: Handle = {module: "production"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {view: "production"diff --git a/apps/erp/app/routes/x+/journal-entry+/$journalEntryId.tsx b/apps/erp/app/routes/x+/journal-entry+/$journalEntryId.tsxindex 4a2f4fb89d..a368abdf46 100644--- a/apps/erp/app/routes/x+/journal-entry+/$journalEntryId.tsx+++ b/apps/erp/app/routes/x+/journal-entry+/$journalEntryId.tsx@@ -5,8 +5,12 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import {getActiveDimensionsWithValues,@@ -59,6 +63,11 @@ const journalSourceDocumentMap: Record<}};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["journalEntryId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, companyGroupId } = await requirePermissions(request,diff --git a/apps/erp/app/routes/x+/maintenance+/$dispatchId.tsx b/apps/erp/app/routes/x+/maintenance+/$dispatchId.tsxindex 50fbdc14f5..d21bd4bc86 100644--- a/apps/erp/app/routes/x+/maintenance+/$dispatchId.tsx+++ b/apps/erp/app/routes/x+/maintenance+/$dispatchId.tsx@@ -8,8 +8,12 @@ import { flash } from "@carbon/auth/session.server";import { storage } from "@carbon/files";import type { JSONContent } from "@carbon/react";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import RiskRegisterCard from "~/modules/quality/ui/RiskRegister/RiskRegisterCard";@@ -49,6 +53,11 @@ async function getMaintenanceDispatchFiles(return result.data ?? [];}+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["dispatchId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources"diff --git a/apps/erp/app/routes/x+/material+/$itemId.purchasing.$supplierPartId.tsx b/apps/erp/app/routes/x+/material+/$itemId.purchasing.$supplierPartId.tsxindex 2f007de9ab..ae00e4be04 100644--- a/apps/erp/app/routes/x+/material+/$itemId.purchasing.$supplierPartId.tsx+++ b/apps/erp/app/routes/x+/material+/$itemId.purchasing.$supplierPartId.tsx@@ -7,7 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { useRouteData } from "@carbon/react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData, useNavigate, useParams } from "react-router";import type { MaterialSummary } from "~/modules/items";import { supplierPartValidator, upsertSupplierPart } from "~/modules/items";@@ -16,6 +21,11 @@ import { getDatabaseClient } from "~/services/database.server";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId", "supplierPartId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/material+/$itemId.purchasing.tsx b/apps/erp/app/routes/x+/material+/$itemId.purchasing.tsxindex 8a5417b5cf..dbb107d567 100644--- a/apps/erp/app/routes/x+/material+/$itemId.purchasing.tsx+++ b/apps/erp/app/routes/x+/material+/$itemId.purchasing.tsx@@ -7,8 +7,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { Suspense } from "react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Await, redirect, useLoaderData, useParams } from "react-router";import { useRouteData } from "~/hooks";import { getBatchProperties } from "~/modules/inventory";@@ -24,6 +29,11 @@ import { ItemPurchasingForm, SupplierParts } from "~/modules/items/ui/Item";import { ItemCostHistoryChart } from "~/modules/items/ui/Item/ItemCostHistoryChart";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/material+/$itemId.tsx b/apps/erp/app/routes/x+/material+/$itemId.tsxindex 6b9d875118..8ec78c68f8 100644--- a/apps/erp/app/routes/x+/material+/$itemId.tsx+++ b/apps/erp/app/routes/x+/material+/$itemId.tsx@@ -6,9 +6,13 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { useRouteData } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Suspense } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Await,Outlet,@@ -46,6 +50,11 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/material+/_layout.tsx b/apps/erp/app/routes/x+/material+/_layout.tsxindex 352f2280bc..2140ae7f11 100644--- a/apps/erp/app/routes/x+/material+/_layout.tsx+++ b/apps/erp/app/routes/x+/material+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import {getMaterialFormsList,@@ -25,6 +30,9 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/part+/$itemId.details.tsx b/apps/erp/app/routes/x+/part+/$itemId.details.tsxindex 7556a19f73..a441be65a8 100644--- a/apps/erp/app/routes/x+/part+/$itemId.details.tsx+++ b/apps/erp/app/routes/x+/part+/$itemId.details.tsx@@ -123,18 +123,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {]);const configData = partManufacturing.data?.requiresConfiguration- ? {- configurationParametersAndGroups: await getConfigurationParameters(- client,- itemId,- companyId- ),- configurationRules: await getConfigurationRules(- client,- itemId,- companyId- )- }+ ? await Promise.all([+ getConfigurationParameters(client, itemId, companyId),+ getConfigurationRules(client, itemId, companyId)+ ]).then(([configurationParametersAndGroups, configurationRules]) => ({+ configurationParametersAndGroups,+ configurationRules+ })): {configurationParametersAndGroups: { groups: [], parameters: [] },configurationRules: []diff --git a/apps/erp/app/routes/x+/part+/$itemId.make.$makeMethodId.tsx b/apps/erp/app/routes/x+/part+/$itemId.make.$makeMethodId.tsxindex c5db5325da..93042c8bb5 100644--- a/apps/erp/app/routes/x+/part+/$itemId.make.$makeMethodId.tsx+++ b/apps/erp/app/routes/x+/part+/$itemId.make.$makeMethodId.tsx@@ -89,18 +89,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}const configData = partManufacturing.data?.requiresConfiguration- ? {- configurationParametersAndGroups: await getConfigurationParameters(- client,- itemId,- companyId- ),- configurationRules: await getConfigurationRules(- client,- itemId,- companyId- )- }+ ? await Promise.all([+ getConfigurationParameters(client, itemId, companyId),+ getConfigurationRules(client, itemId, companyId)+ ]).then(([configurationParametersAndGroups, configurationRules]) => ({+ configurationParametersAndGroups,+ configurationRules+ })): {configurationParametersAndGroups: { groups: [], parameters: [] },configurationRules: []diff --git a/apps/erp/app/routes/x+/part+/$itemId.purchasing.$supplierPartId.tsx b/apps/erp/app/routes/x+/part+/$itemId.purchasing.$supplierPartId.tsxindex 571a4d15ae..51a649c1e0 100644--- a/apps/erp/app/routes/x+/part+/$itemId.purchasing.$supplierPartId.tsx+++ b/apps/erp/app/routes/x+/part+/$itemId.purchasing.$supplierPartId.tsx@@ -6,7 +6,12 @@ import { assertIsPost } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { validator } from "@carbon/form";import { useRouteData } from "@carbon/react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { useLoaderData, useNavigate, useParams } from "react-router";import type { PartSummary } from "~/modules/items";import { supplierPartValidator, upsertSupplierPart } from "~/modules/items";@@ -15,6 +20,11 @@ import { getDatabaseClient } from "~/services/database.server";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId", "supplierPartId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/part+/$itemId.purchasing.tsx b/apps/erp/app/routes/x+/part+/$itemId.purchasing.tsxindex 36ca18932f..6cd88f51b6 100644--- a/apps/erp/app/routes/x+/part+/$itemId.purchasing.tsx+++ b/apps/erp/app/routes/x+/part+/$itemId.purchasing.tsx@@ -7,8 +7,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { Suspense } from "react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Await, redirect, useLoaderData, useParams } from "react-router";import { useRouteData } from "~/hooks";import { getBatchProperties } from "~/modules/inventory";@@ -24,6 +29,11 @@ import { ItemPurchasingForm, SupplierParts } from "~/modules/items/ui/Item";import { ItemCostHistoryChart } from "~/modules/items/ui/Item/ItemCostHistoryChart";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/part+/$itemId.sales.tsx b/apps/erp/app/routes/x+/part+/$itemId.sales.tsxindex 3ca6e90c41..4178a105be 100644--- a/apps/erp/app/routes/x+/part+/$itemId.sales.tsx+++ b/apps/erp/app/routes/x+/part+/$itemId.sales.tsx@@ -11,7 +11,12 @@ import {} from "@carbon/ee/rules";import { validationError, validator } from "@carbon/form";import { VStack } from "@carbon/react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData } from "react-router";import {getItemCustomerParts,@@ -25,6 +30,11 @@ import { SalesRuleAssignmentsList } from "~/modules/sales/ui/SalesRules";import { getCustomFields, setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/part+/$itemId.tsx b/apps/erp/app/routes/x+/part+/$itemId.tsxindex f3e4b555ee..d9631a2b1c 100644--- a/apps/erp/app/routes/x+/part+/$itemId.tsx+++ b/apps/erp/app/routes/x+/part+/$itemId.tsx@@ -17,11 +17,15 @@ import {TabsTrigger,useRouteData} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans, useLingui } from "@lingui/react/macro";import { Suspense, useState } from "react";import { LuSearch } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Await,Outlet,@@ -72,6 +76,11 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"], search: ["methodId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/part+/_layout.tsx b/apps/erp/app/routes/x+/part+/_layout.tsxindex 50d5a66d5b..6b79044abe 100644--- a/apps/erp/app/routes/x+/part+/_layout.tsx+++ b/apps/erp/app/routes/x+/part+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import { getUnitOfMeasuresList } from "~/modules/items";import { getLocationsList } from "~/modules/resources";@@ -21,6 +26,9 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/payments+/$paymentId.tsx b/apps/erp/app/routes/x+/payments+/$paymentId.tsxindex 09dcdf0a16..c9a4b94a87 100644--- a/apps/erp/app/routes/x+/payments+/$paymentId.tsx+++ b/apps/erp/app/routes/x+/payments+/$paymentId.tsx@@ -8,8 +8,13 @@ import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { VStack } from "@carbon/react";import type { FundingSource } from "@carbon/utils";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, redirect, useLoaderData } from "react-router";import {AvailableCreditsTable,@@ -41,6 +46,11 @@ export const handle: Handle = {module: "invoicing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["paymentId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "invoicing"diff --git a/apps/erp/app/routes/x+/people+/attributes.list.$categoryId.tsx b/apps/erp/app/routes/x+/people+/attributes.list.$categoryId.tsxindex 8ddbf83b83..ebc98bb7b4 100644--- a/apps/erp/app/routes/x+/people+/attributes.list.$categoryId.tsx+++ b/apps/erp/app/routes/x+/people+/attributes.list.$categoryId.tsx@@ -5,7 +5,12 @@import { assertIsPost, error, notFound } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {data,Outlet,@@ -21,6 +26,11 @@ import {import { AttributeCategoryDetail } from "~/modules/people/ui/Attributes";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["categoryId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "people",diff --git a/apps/erp/app/routes/x+/people+/attributes.tsx b/apps/erp/app/routes/x+/people+/attributes.tsxindex c8b3955e7a..88db8ab36c 100644--- a/apps/erp/app/routes/x+/people+/attributes.tsx+++ b/apps/erp/app/routes/x+/people+/attributes.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import {getAttributeCategories,@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.attributes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "people",diff --git a/apps/erp/app/routes/x+/people+/departments.tsx b/apps/erp/app/routes/x+/people+/departments.tsxindex db00ceaade..e95f98611c 100644--- a/apps/erp/app/routes/x+/people+/departments.tsx+++ b/apps/erp/app/routes/x+/people+/departments.tsx@@ -21,12 +21,16 @@ import {TabsList,TabsTrigger} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans, useLingui } from "@lingui/react/macro";import { useCallback, useState } from "react";import { BsThreeDotsVertical } from "react-icons/bs";import { LuDownload } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData, useNavigate } from "react-router";import { New } from "~/components";import { ImportCSVModal } from "~/components/ImportCSVModal";@@ -43,6 +47,9 @@ export const handle: Handle = {to: path.to.departments};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "people",diff --git a/apps/erp/app/routes/x+/people+/holidays.tsx b/apps/erp/app/routes/x+/people+/holidays.tsxindex bec435c4ad..3facede3f0 100644--- a/apps/erp/app/routes/x+/people+/holidays.tsx+++ b/apps/erp/app/routes/x+/people+/holidays.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getHolidays, getHolidayYears } from "~/modules/people";import { HolidaysTable } from "~/modules/people/ui/Holidays";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.holidays};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "people",diff --git a/apps/erp/app/routes/x+/people+/shifts.tsx b/apps/erp/app/routes/x+/people+/shifts.tsxindex 86773f4345..ecb30e4775 100644--- a/apps/erp/app/routes/x+/people+/shifts.tsx+++ b/apps/erp/app/routes/x+/people+/shifts.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getShifts } from "~/modules/people";import { ShiftsTable } from "~/modules/people/ui/Shifts";@@ -21,6 +25,11 @@ export const handle: Handle = {to: path.to.shifts};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "people",diff --git a/apps/erp/app/routes/x+/people+/timecard.tsx b/apps/erp/app/routes/x+/people+/timecard.tsxindex c84094dc4b..6d5dbfb361 100644--- a/apps/erp/app/routes/x+/people+/timecard.tsx+++ b/apps/erp/app/routes/x+/people+/timecard.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getTimecardEntries } from "~/modules/people";import { TimecardsTable } from "~/modules/people/ui/Timecards";@@ -21,6 +25,11 @@ export const handle: Handle = {to: path.to.peopleTimecard};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "people"diff --git a/apps/erp/app/routes/x+/person+/$personId.tsx b/apps/erp/app/routes/x+/person+/$personId.tsxindex c7ac0fa11f..403fec6d2c 100644--- a/apps/erp/app/routes/x+/person+/$personId.tsx+++ b/apps/erp/app/routes/x+/person+/$personId.tsx@@ -6,8 +6,13 @@ import { assertIsPost, error, success } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, Outlet, redirect, useLoaderData } from "react-router";import {accountProfileValidator,@@ -31,6 +36,11 @@ export const handle: Handle = {module: "people"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["personId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "people"diff --git a/apps/erp/app/routes/x+/person+/_layout.tsx b/apps/erp/app/routes/x+/person+/_layout.tsxindex 97e9193cc4..8392787803 100644--- a/apps/erp/app/routes/x+/person+/_layout.tsx+++ b/apps/erp/app/routes/x+/person+/_layout.tsx@@ -4,13 +4,21 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";export const meta: MetaFunction = () => {return [{ title: "Carbon | People" }];};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {view: "people"diff --git a/apps/erp/app/routes/x+/picking-list+/$pickingListId.tracked.$lineId.tsx b/apps/erp/app/routes/x+/picking-list+/$pickingListId.tracked.$lineId.tsxindex 17c1f4cf07..8659e01058 100644--- a/apps/erp/app/routes/x+/picking-list+/$pickingListId.tracked.$lineId.tsx+++ b/apps/erp/app/routes/x+/picking-list+/$pickingListId.tracked.$lineId.tsx@@ -44,18 +44,22 @@ export async function loader({ request, params }: LoaderFunctionArgs) {(line.item as { itemTrackingType: string } | null)?.itemTrackingType ??"Batch";- const entities = locationId- ? await getAvailableTrackedEntities(client, {- itemId: line.itemId,- companyId,- locationId,- excludeLineside: true,- excludeAllocated: true,- excludeLineId: lineId- })- : { data: [] };-- const settings = await getCompanySettings(client, companyId);+ const [entities, settings, defaultOrder] = await Promise.all([+ locationId+ ? getAvailableTrackedEntities(client, {+ itemId: line.itemId,+ companyId,+ locationId,+ excludeLineside: true,+ excludeAllocated: true,+ excludeLineId: lineId+ })+ : { data: [] },+ getCompanySettings(client, companyId),+ locationId+ ? getPickOrder(client, { itemId: line.itemId, locationId, companyId })+ : ("Default" as const)+ ]);const shelfLife = (settings.data?.inventoryShelfLife ?? {}) as {nearExpiryWarningDays?: number | null;expiredEntityPolicy?: "Warn" | "Block" | "BlockWithOverride";@@ -70,13 +74,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {),nearExpiryWarningDays: shelfLife.nearExpiryWarningDays ?? 0,expiredEntityPolicy: shelfLife.expiredEntityPolicy ?? "Warn",- defaultOrder: locationId- ? await getPickOrder(client, {- itemId: line.itemId,- locationId,- companyId- })- : "Default"+ defaultOrder};}diff --git a/apps/erp/app/routes/x+/picking-list+/$pickingListId.tsx b/apps/erp/app/routes/x+/picking-list+/$pickingListId.tsxindex 50860215ea..6a58bba1ce 100644--- a/apps/erp/app/routes/x+/picking-list+/$pickingListId.tsx+++ b/apps/erp/app/routes/x+/picking-list+/$pickingListId.tsx@@ -5,8 +5,12 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import {getPickingList,@@ -26,6 +30,11 @@ export const handle: Handle = {module: "inventory"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["pickingListId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/priority+/dates.tsx b/apps/erp/app/routes/x+/priority+/dates.tsxindex 15c68e8448..7b6c287be3 100644--- a/apps/erp/app/routes/x+/priority+/dates.tsx+++ b/apps/erp/app/routes/x+/priority+/dates.tsx@@ -26,6 +26,7 @@ import {useLocalStorage,VStack} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import {endOfMonth,endOfWeek,@@ -40,7 +41,10 @@ import { Trans, useLingui } from "@lingui/react/macro";import { useLocale } from "@react-aria/i18n";import { useCallback, useEffect, useMemo, useState } from "react";import { LuChevronLeft, LuChevronRight, LuSettings2 } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {redirect,useLoaderData,@@ -76,6 +80,11 @@ export const handle: Handle = {type ViewType = "week" | "month";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/priority+/operations.tsx b/apps/erp/app/routes/x+/priority+/operations.tsxindex bb64d819bc..3560b1e0f2 100644--- a/apps/erp/app/routes/x+/priority+/operations.tsx+++ b/apps/erp/app/routes/x+/priority+/operations.tsx@@ -26,6 +26,7 @@ import {useRealtimeChannel,VStack} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import {getLocalTimeZone,now,@@ -41,7 +42,10 @@ import {LuSettings2,LuTriangleAlert} from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Link, useLoaderData } from "react-router";import { SearchFilter } from "~/components";import { Enumerable } from "~/components/Enumerable";@@ -80,6 +84,11 @@ export const handle: Handle = {module: "schedule"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/procedure+/$id.tsx b/apps/erp/app/routes/x+/procedure+/$id.tsxindex d183897948..cbeec1f163 100644--- a/apps/erp/app/routes/x+/procedure+/$id.tsx+++ b/apps/erp/app/routes/x+/procedure+/$id.tsx@@ -9,11 +9,15 @@ import { getLogger } from "@carbon/logger";import type { JSONContent } from "@carbon/react";import { generateHTML, useDebounce } from "@carbon/react";import { Editor } from "@carbon/react/Editor";+import { isUnaffectedByNavigation } from "@carbon/utils";import { getLocalTimeZone, today } from "@internationalized/date";import { msg } from "@lingui/core/macro";import { useLingui } from "@lingui/react/macro";import { useEffect, useState } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Outlet,redirect,@@ -43,6 +47,11 @@ export const handle: Handle = {module: "production"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/production+/assemblies.tsx b/apps/erp/app/routes/x+/production+/assemblies.tsxindex cd8eb820b9..070f8e04e5 100644--- a/apps/erp/app/routes/x+/production+/assemblies.tsx+++ b/apps/erp/app/routes/x+/production+/assemblies.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getAssemblyInstructions } from "~/modules/production";import AssemblyInstructionsTable from "~/modules/production/ui/Assemblies/AssemblyInstructionsTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.assemblyInstructions};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/production+/batches.tsx b/apps/erp/app/routes/x+/production+/batches.tsxindex b6e7619408..e11cdafc0d 100644--- a/apps/erp/app/routes/x+/production+/batches.tsx+++ b/apps/erp/app/routes/x+/production+/batches.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import {getJobOperationBatches,@@ -22,6 +26,11 @@ export const handle: Handle = {to: path.to.operationBatches};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/production+/demand-forecasts.tsx b/apps/erp/app/routes/x+/production+/demand-forecasts.tsxindex 1c5ca1206e..d5aa3792ca 100644--- a/apps/erp/app/routes/x+/production+/demand-forecasts.tsx+++ b/apps/erp/app/routes/x+/production+/demand-forecasts.tsx@@ -6,10 +6,13 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";-import { datetime } from "@carbon/utils";+import { datetime, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans } from "@lingui/react/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import { getProductionProjections } from "~/modules/production";@@ -29,6 +32,11 @@ export const handle: Handle = {export const WEEKS_TO_PROJECT = 12 * 4;+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/production+/planning.tsx b/apps/erp/app/routes/x+/production+/planning.tsxindex 5bf5f39f87..1580d9700b 100644--- a/apps/erp/app/routes/x+/production+/planning.tsx+++ b/apps/erp/app/routes/x+/production+/planning.tsx@@ -6,9 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { ResizablePanel, ResizablePanelGroup, VStack } from "@carbon/react";-import { datetime } from "@carbon/utils";+import { datetime, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import type { ProductionPlanningItem } from "~/modules/production";import { getProductionPlanning } from "~/modules/production";@@ -27,6 +30,11 @@ export const handle: Handle = {to: path.to.productionPlanning};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/production+/procedures.tsx b/apps/erp/app/routes/x+/production+/procedures.tsxindex e6aa1d5dce..46c5726600 100644--- a/apps/erp/app/routes/x+/production+/procedures.tsx+++ b/apps/erp/app/routes/x+/production+/procedures.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getProcedures } from "~/modules/production";import ProceduresTable from "~/modules/production/ui/Procedures/ProceduresTable";@@ -19,6 +23,11 @@ export const handle: Handle = {to: path.to.procedures};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/production+/scrap-reasons.tsx b/apps/erp/app/routes/x+/production+/scrap-reasons.tsxindex 50b0e50e33..132d3c4ecb 100644--- a/apps/erp/app/routes/x+/production+/scrap-reasons.tsx+++ b/apps/erp/app/routes/x+/production+/scrap-reasons.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getScrapReasons } from "~/modules/production";import ScrapReasonsTable from "~/modules/production/ui/ScrapReasons/ScrapReasonsTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.scrapReasons};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "production",diff --git a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.tsx b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.tsxindex 347ad117c2..425be0ed33 100644--- a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.tsx+++ b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.tsx@@ -6,8 +6,13 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout";import { getCurrencyByCode } from "~/modules/accounting";@@ -36,6 +41,11 @@ export const handle: Handle = {module: "invoicing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["invoiceId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, companyGroupId } = await requirePermissions(request,diff --git a/apps/erp/app/routes/x+/purchase-order+/$orderId.tsx b/apps/erp/app/routes/x+/purchase-order+/$orderId.tsxindex 77878b87ff..76d4fb51c9 100644--- a/apps/erp/app/routes/x+/purchase-order+/$orderId.tsx+++ b/apps/erp/app/routes/x+/purchase-order+/$orderId.tsx@@ -22,10 +22,15 @@ import { trigger } from "@carbon/jobs";import { getLogger } from "@carbon/logger";import { NotificationEvent } from "@carbon/notifications";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { renderAsync } from "@react-email/components";import { parseAcceptLanguage } from "intl-parse-accept-language";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import { getCurrencyByCode, getPaymentTermsList } from "~/modules/accounting";@@ -400,6 +405,11 @@ export async function action(args: ActionFunctionArgs) {);}+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["orderId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, companyGroupId, userId } =await requirePermissions(request, {diff --git a/apps/erp/app/routes/x+/purchase-return-order+/$id.tsx b/apps/erp/app/routes/x+/purchase-return-order+/$id.tsxindex d2dc57e626..7eecff5275 100644--- a/apps/erp/app/routes/x+/purchase-return-order+/$id.tsx+++ b/apps/erp/app/routes/x+/purchase-return-order+/$id.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import {@@ -31,6 +35,11 @@ export const handle: Handle = {module: "purchasing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/purchasing+/orders.tsx b/apps/erp/app/routes/x+/purchasing+/orders.tsxindex b44fec815b..56ebaaea83 100644--- a/apps/erp/app/routes/x+/purchasing+/orders.tsx+++ b/apps/erp/app/routes/x+/purchasing+/orders.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getPurchaseOrders } from "~/modules/purchasing";import { PurchaseOrdersTable } from "~/modules/purchasing/ui/PurchaseOrder";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.purchaseOrders};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "purchasing",diff --git a/apps/erp/app/routes/x+/purchasing+/planning.tsx b/apps/erp/app/routes/x+/purchasing+/planning.tsxindex e95f3ca852..a67081e842 100644--- a/apps/erp/app/routes/x+/purchasing+/planning.tsx+++ b/apps/erp/app/routes/x+/purchasing+/planning.tsx@@ -6,9 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { ResizablePanel, ResizablePanelGroup, VStack } from "@carbon/react";-import { datetime } from "@carbon/utils";+import { datetime, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import type { PurchasingPlanningItem } from "~/modules/purchasing";import { getPurchasingPlanning } from "~/modules/purchasing";@@ -27,6 +30,11 @@ export const handle: Handle = {to: path.to.purchasingPlanning};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "purchasing",diff --git a/apps/erp/app/routes/x+/purchasing+/quotes.tsx b/apps/erp/app/routes/x+/purchasing+/quotes.tsxindex c471ca1f1c..950c2456e3 100644--- a/apps/erp/app/routes/x+/purchasing+/quotes.tsx+++ b/apps/erp/app/routes/x+/purchasing+/quotes.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getSupplierQuotes } from "~/modules/purchasing/purchasing.service";import { SupplierQuotesTable } from "~/modules/purchasing/ui/SupplierQuote";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.supplierQuotes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "purchasing",diff --git a/apps/erp/app/routes/x+/purchasing+/supplier-types.tsx b/apps/erp/app/routes/x+/purchasing+/supplier-types.tsxindex 668b12e9a6..9fbf007b24 100644--- a/apps/erp/app/routes/x+/purchasing+/supplier-types.tsx+++ b/apps/erp/app/routes/x+/purchasing+/supplier-types.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getSupplierTypes } from "~/modules/purchasing";import { SupplierTypesTable } from "~/modules/purchasing/ui/SupplierTypes";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.supplierTypes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "purchasing",diff --git a/apps/erp/app/routes/x+/purchasing-rfq+/$rfqId.tsx b/apps/erp/app/routes/x+/purchasing-rfq+/$rfqId.tsxindex d856df6d82..4ab177bb4b 100644--- a/apps/erp/app/routes/x+/purchasing-rfq+/$rfqId.tsx+++ b/apps/erp/app/routes/x+/purchasing-rfq+/$rfqId.tsx@@ -8,8 +8,12 @@ import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { type JSONContent, VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import type { PurchasingRFQLine } from "~/modules/purchasing";@@ -38,6 +42,11 @@ export const handle: Handle = {module: "purchasing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["rfqId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { companyId } = await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/quality+/calibrations.tsx b/apps/erp/app/routes/x+/quality+/calibrations.tsxindex ea2fcd886b..4ea3315296 100644--- a/apps/erp/app/routes/x+/quality+/calibrations.tsx+++ b/apps/erp/app/routes/x+/quality+/calibrations.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import {getGaugeCalibrationRecords,@@ -22,6 +26,11 @@ export const handle: Handle = {to: path.to.gauges};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/quality+/documents.tsx b/apps/erp/app/routes/x+/quality+/documents.tsxindex 832c5d6d5d..a51eff94ef 100644--- a/apps/erp/app/routes/x+/quality+/documents.tsx+++ b/apps/erp/app/routes/x+/quality+/documents.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getQualityDocuments } from "~/modules/quality";import QualityDocumentsTable from "~/modules/quality/ui/Documents/QualityDocumentsTable";@@ -19,6 +23,11 @@ export const handle: Handle = {to: path.to.qualityDocuments};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/quality+/gauge-types.tsx b/apps/erp/app/routes/x+/quality+/gauge-types.tsxindex 89b837a782..8a80e0596a 100644--- a/apps/erp/app/routes/x+/quality+/gauge-types.tsx+++ b/apps/erp/app/routes/x+/quality+/gauge-types.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getGaugeTypes } from "~/modules/quality";import GaugeTypesTable from "~/modules/quality/ui/GaugeTypes/GaugeTypesTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.gaugeTypes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/quality+/gauges.tsx b/apps/erp/app/routes/x+/quality+/gauges.tsxindex 9c535df046..ef39175038 100644--- a/apps/erp/app/routes/x+/quality+/gauges.tsx+++ b/apps/erp/app/routes/x+/quality+/gauges.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getGauges, getGaugeTypesList } from "~/modules/quality";import GaugesTable from "~/modules/quality/ui/Gauge/GaugesTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.gauges};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/quality+/inspection-plans.tsx b/apps/erp/app/routes/x+/quality+/inspection-plans.tsxindex 4496c65d46..8424c76dbc 100644--- a/apps/erp/app/routes/x+/quality+/inspection-plans.tsx+++ b/apps/erp/app/routes/x+/quality+/inspection-plans.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getInspectionDocuments } from "~/modules/quality";import { InspectionDocumentTable } from "~/modules/quality/ui/InspectionDocument";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.inspectionDocuments};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/quality+/issue-types.tsx b/apps/erp/app/routes/x+/quality+/issue-types.tsxindex dc527435b2..6f13469fcf 100644--- a/apps/erp/app/routes/x+/quality+/issue-types.tsx+++ b/apps/erp/app/routes/x+/quality+/issue-types.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getIssueTypes } from "~/modules/quality";import IssueTypesTable from "~/modules/quality/ui/IssueTypes/IssueTypesTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.issueTypes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/quality+/required-actions.tsx b/apps/erp/app/routes/x+/quality+/required-actions.tsxindex 24651a2464..f24583ace8 100644--- a/apps/erp/app/routes/x+/quality+/required-actions.tsx+++ b/apps/erp/app/routes/x+/quality+/required-actions.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getRequiredActions } from "~/modules/quality";import RequiredActionsTable from "~/modules/quality/ui/RequiredActions/RequiredActionsTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.requiredActions};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/quality+/risks.tsx b/apps/erp/app/routes/x+/quality+/risks.tsxindex da1347ac6c..769dd87e00 100644--- a/apps/erp/app/routes/x+/quality+/risks.tsx+++ b/apps/erp/app/routes/x+/quality+/risks.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, Outlet, redirect, useLoaderData } from "react-router";import { getRisks } from "~/modules/quality/quality.service";import type { Risk } from "~/modules/quality/types";@@ -21,6 +25,11 @@ export const handle: Handle = {to: path.to.risks};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "quality",diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.tsxindex 341606581b..30359ae68f 100644--- a/apps/erp/app/routes/x+/quote+/$quoteId.tsx+++ b/apps/erp/app/routes/x+/quote+/$quoteId.tsx@@ -6,12 +6,16 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import type { DragEndEvent } from "@dnd-kit/core";import { DndContext } from "@dnd-kit/core";import { msg } from "@lingui/core/macro";import type { FileObject } from "@supabase/storage-js";import type { PostgrestResponse } from "@supabase/supabase-js";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Outlet,redirect,@@ -53,6 +57,11 @@ export const handle: Handle = {module: "sales"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["quoteId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/quote+/_layout.tsx b/apps/erp/app/routes/x+/quote+/_layout.tsxindex a1c64a999a..bc1c886628 100644--- a/apps/erp/app/routes/x+/quote+/_layout.tsx+++ b/apps/erp/app/routes/x+/quote+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -19,6 +24,9 @@ export const handle: Handle = {module: "sales"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {view: "sales"diff --git a/apps/erp/app/routes/x+/receipt+/$receiptId.tsx b/apps/erp/app/routes/x+/receipt+/$receiptId.tsxindex 1f0ff5a3cd..46e58688a0 100644--- a/apps/erp/app/routes/x+/receipt+/$receiptId.tsx+++ b/apps/erp/app/routes/x+/receipt+/$receiptId.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import {getBatchProperties,@@ -30,6 +34,11 @@ export const handle: Handle = {module: "inventory"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["receiptId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { companyId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/reports+/inventory-valuation.tsx b/apps/erp/app/routes/x+/reports+/inventory-valuation.tsxindex 53f46426e2..117c103571 100644--- a/apps/erp/app/routes/x+/reports+/inventory-valuation.tsx+++ b/apps/erp/app/routes/x+/reports+/inventory-valuation.tsx@@ -3,9 +3,12 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";-import { datetime } from "@carbon/utils";+import { datetime, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { useLoaderData } from "react-router";import {getInventoryValuation,@@ -23,6 +26,11 @@ export const handle: Handle = {module: "accounting"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "accounting"diff --git a/apps/erp/app/routes/x+/resources+/abilities.tsx b/apps/erp/app/routes/x+/resources+/abilities.tsxindex 4407a15620..4029554594 100644--- a/apps/erp/app/routes/x+/resources+/abilities.tsx+++ b/apps/erp/app/routes/x+/resources+/abilities.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { AbilitiesTable, getAbilities } from "~/modules/resources";import type { Handle } from "~/utils/handle";@@ -19,6 +23,11 @@ export const handle: Handle = {to: path.to.abilities};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/ability.$id.tsx b/apps/erp/app/routes/x+/resources+/ability.$id.tsxindex ebaaad4562..095728e042 100644--- a/apps/erp/app/routes/x+/resources+/ability.$id.tsx+++ b/apps/erp/app/routes/x+/resources+/ability.$id.tsx@@ -6,8 +6,12 @@ import { error, notFound } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { AbilityEmployeesTable, getAbility } from "~/modules/resources";import type { Handle } from "~/utils/handle";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.abilities};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/assignments.assignment.$assignmentId.tsx b/apps/erp/app/routes/x+/resources+/assignments.assignment.$assignmentId.tsxindex 78e4888a30..7212eab43c 100644--- a/apps/erp/app/routes/x+/resources+/assignments.assignment.$assignmentId.tsx+++ b/apps/erp/app/routes/x+/resources+/assignments.assignment.$assignmentId.tsx@@ -9,8 +9,13 @@ import { validationError, validator } from "@carbon/form";import { trigger } from "@carbon/jobs";import { getLogger } from "@carbon/logger";import { NotificationEvent } from "@carbon/notifications";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {data,redirect,@@ -40,6 +45,11 @@ export const handle: Handle = {to: path.to.trainingAssignments};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["assignmentId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/assignments.tsx b/apps/erp/app/routes/x+/resources+/assignments.tsxindex 78fba48537..fb61885e98 100644--- a/apps/erp/app/routes/x+/resources+/assignments.tsx+++ b/apps/erp/app/routes/x+/resources+/assignments.tsx@@ -13,6 +13,7 @@ import {MenuItem,VStack} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans, useLingui } from "@lingui/react/macro";import type { ColumnDef } from "@tanstack/react-table";@@ -29,7 +30,10 @@ import {LuTriangleAlert,LuUsers} from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Link,Outlet,@@ -52,6 +56,9 @@ export const handle: Handle = {to: path.to.trainingAssignments};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/contractors.tsx b/apps/erp/app/routes/x+/resources+/contractors.tsxindex d10c021a88..59cfd79b0f 100644--- a/apps/erp/app/routes/x+/resources+/contractors.tsx+++ b/apps/erp/app/routes/x+/resources+/contractors.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import {ContractorsTable,@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.contractors};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/failure-modes.tsx b/apps/erp/app/routes/x+/resources+/failure-modes.tsxindex c5245d0558..235b153067 100644--- a/apps/erp/app/routes/x+/resources+/failure-modes.tsx+++ b/apps/erp/app/routes/x+/resources+/failure-modes.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getFailureModes } from "~/modules/resources";import FailureModesTable from "~/modules/resources/ui/FailureModes/FailureModesTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.failureModes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/locations.tsx b/apps/erp/app/routes/x+/resources+/locations.tsxindex 1fd016b3bc..3d0cdd9138 100644--- a/apps/erp/app/routes/x+/resources+/locations.tsx+++ b/apps/erp/app/routes/x+/resources+/locations.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getLocations, LocationsTable } from "~/modules/resources";import type { Handle } from "~/utils/handle";@@ -19,6 +23,11 @@ export const handle: Handle = {to: path.to.locations};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/maintenance.tsx b/apps/erp/app/routes/x+/resources+/maintenance.tsxindex cd0bdb10c5..7bd2835a24 100644--- a/apps/erp/app/routes/x+/resources+/maintenance.tsx+++ b/apps/erp/app/routes/x+/resources+/maintenance.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import {getFailureModesList,@@ -22,6 +26,11 @@ export const handle: Handle = {to: path.to.maintenanceDispatches};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/partners.tsx b/apps/erp/app/routes/x+/resources+/partners.tsxindex c4f03178ce..0563c272e5 100644--- a/apps/erp/app/routes/x+/resources+/partners.tsx+++ b/apps/erp/app/routes/x+/resources+/partners.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import {getAbilitiesList,@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.partners};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/processes.tsx b/apps/erp/app/routes/x+/resources+/processes.tsxindex e15ecb7360..fbe2e0790b 100644--- a/apps/erp/app/routes/x+/resources+/processes.tsx+++ b/apps/erp/app/routes/x+/resources+/processes.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getProcesses, ProcessesTable } from "~/modules/resources";import type { Handle } from "~/utils/handle";@@ -19,6 +23,11 @@ export const handle: Handle = {to: path.to.processes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/scheduled-maintenance.tsx b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.tsxindex c015a24a71..7fe7ea6b9f 100644--- a/apps/erp/app/routes/x+/resources+/scheduled-maintenance.tsx+++ b/apps/erp/app/routes/x+/resources+/scheduled-maintenance.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, Outlet, useLoaderData } from "react-router";import type { MaintenanceSchedule } from "~/modules/resources";import {@@ -24,6 +28,11 @@ export const handle: Handle = {to: path.to.maintenanceSchedules};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/suggestions.tsx b/apps/erp/app/routes/x+/resources+/suggestions.tsxindex 7f1272ba7e..cb141689bc 100644--- a/apps/erp/app/routes/x+/resources+/suggestions.tsx+++ b/apps/erp/app/routes/x+/resources+/suggestions.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getSuggestions, SuggestionsTable } from "~/modules/resources";import { getTagsList } from "~/modules/shared";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.suggestions};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/training.tsx b/apps/erp/app/routes/x+/resources+/training.tsxindex 0f4fcc7578..fc236891f4 100644--- a/apps/erp/app/routes/x+/resources+/training.tsx+++ b/apps/erp/app/routes/x+/resources+/training.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getTrainings, TrainingsTable } from "~/modules/resources";import { getTagsList } from "~/modules/shared";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.trainings};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/resources+/work-centers.tsx b/apps/erp/app/routes/x+/resources+/work-centers.tsxindex c90e312817..dcfb705abb 100644--- a/apps/erp/app/routes/x+/resources+/work-centers.tsx+++ b/apps/erp/app/routes/x+/resources+/work-centers.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getDepartmentsList } from "~/modules/people";import {@@ -24,6 +28,11 @@ export const handle: Handle = {to: path.to.workCenters};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/sales+/customer-portals.tsx b/apps/erp/app/routes/x+/sales+/customer-portals.tsxindex 0fc3160541..4fe866110b 100644--- a/apps/erp/app/routes/x+/sales+/customer-portals.tsx+++ b/apps/erp/app/routes/x+/sales+/customer-portals.tsx@@ -5,8 +5,12 @@import { getAppUrl } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import {@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.customerPortals};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/customer-statuses.tsx b/apps/erp/app/routes/x+/sales+/customer-statuses.tsxindex bd6d861c49..72c075b31f 100644--- a/apps/erp/app/routes/x+/sales+/customer-statuses.tsx+++ b/apps/erp/app/routes/x+/sales+/customer-statuses.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getCustomerStatuses } from "~/modules/sales";import { CustomerStatusesTable } from "~/modules/sales/ui/CustomerStatuses";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.customerStatuses};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/customer-types.tsx b/apps/erp/app/routes/x+/sales+/customer-types.tsxindex d9f6aa16ea..ddf8c62de1 100644--- a/apps/erp/app/routes/x+/sales+/customer-types.tsx+++ b/apps/erp/app/routes/x+/sales+/customer-types.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getCustomerTypes } from "~/modules/sales";import { CustomerTypesTable } from "~/modules/sales/ui/CustomerTypes";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.customerTypes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/no-quote-reasons.tsx b/apps/erp/app/routes/x+/sales+/no-quote-reasons.tsxindex 5e07af4b6a..4455d59f7a 100644--- a/apps/erp/app/routes/x+/sales+/no-quote-reasons.tsx+++ b/apps/erp/app/routes/x+/sales+/no-quote-reasons.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getNoQuoteReasons } from "~/modules/sales";import { NoQuoteReasonsTable } from "~/modules/sales/ui/NoQuoteReasons";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.noQuoteReasons};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/price-list.tsx b/apps/erp/app/routes/x+/sales+/price-list.tsxindex 60482e325c..89d689e59a 100644--- a/apps/erp/app/routes/x+/sales+/price-list.tsx+++ b/apps/erp/app/routes/x+/sales+/price-list.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getBaseCatalog, resolvePriceList } from "~/modules/sales";import PriceListTable from "~/modules/sales/ui/Pricing/PriceOverridesTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.salesPriceList};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/pricing-rules.tsx b/apps/erp/app/routes/x+/sales+/pricing-rules.tsxindex ed6d5fa38c..65b488d43c 100644--- a/apps/erp/app/routes/x+/sales+/pricing-rules.tsx+++ b/apps/erp/app/routes/x+/sales+/pricing-rules.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getPricingRules } from "~/modules/sales";import PricingRulesTable from "~/modules/sales/ui/Pricing/PricingRulesTable";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.salesPricingRules};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/quotes.tsx b/apps/erp/app/routes/x+/sales+/quotes.tsxindex fe4a1fed2e..08fc268cfb 100644--- a/apps/erp/app/routes/x+/sales+/quotes.tsx+++ b/apps/erp/app/routes/x+/sales+/quotes.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getQuotes } from "~/modules/sales";import { QuotesTable } from "~/modules/sales/ui/Quotes";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.quotes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/return-reasons.tsx b/apps/erp/app/routes/x+/sales+/return-reasons.tsxindex aa44707d87..fcce91cf62 100644--- a/apps/erp/app/routes/x+/sales+/return-reasons.tsx+++ b/apps/erp/app/routes/x+/sales+/return-reasons.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getReturnReasons } from "~/modules/sales";import { ReturnReasonsTable } from "~/modules/sales/ui/ReturnReasons";@@ -18,6 +22,11 @@ export const handle: Handle = {to: path.to.returnReasons};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/rfqs.tsx b/apps/erp/app/routes/x+/sales+/rfqs.tsxindex 7f9a40333c..305c5a0ee7 100644--- a/apps/erp/app/routes/x+/sales+/rfqs.tsx+++ b/apps/erp/app/routes/x+/sales+/rfqs.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getSalesRFQs } from "~/modules/sales";import { SalesRFQsTable } from "~/modules/sales/ui/SalesRFQ";@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.salesRfqs};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales+/sales-rules.$id.tsx b/apps/erp/app/routes/x+/sales+/sales-rules.$id.tsxindex 2592882797..8f52e9a439 100644--- a/apps/erp/app/routes/x+/sales+/sales-rules.$id.tsx+++ b/apps/erp/app/routes/x+/sales+/sales-rules.$id.tsx@@ -9,7 +9,12 @@ import { requireFeature } from "@carbon/ee/plan.server";import { upsertEnforcementRule } from "@carbon/ee/rules.server";import { validationError, validator } from "@carbon/form";import type { SalesRuleSurface } from "@carbon/utils";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, redirect, useLoaderData, useNavigate } from "react-router";import type { z } from "zod";import { type salesRuleSeverities, salesRuleValidator } from "~/modules/sales";@@ -17,6 +22,11 @@ import { SalesRuleForm } from "~/modules/sales/ui/SalesRules";import { getEnforcementRule } from "~/modules/shared";import { getParams, path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales"diff --git a/apps/erp/app/routes/x+/sales+/sales-rules.tsx b/apps/erp/app/routes/x+/sales+/sales-rules.tsxindex a9ba029403..1c8ab4b4b5 100644--- a/apps/erp/app/routes/x+/sales+/sales-rules.tsx+++ b/apps/erp/app/routes/x+/sales+/sales-rules.tsx@@ -5,8 +5,12 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import {@@ -25,6 +29,9 @@ export const handle: Handle = {to: path.to.salesRules};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.tsx b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.tsxindex 9181639783..35d80d07d9 100644--- a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.tsx+++ b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.tsx@@ -8,8 +8,13 @@ import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";import { createMappingService } from "@carbon/ee/accounting";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout";import { getCurrencyByCode } from "~/modules/accounting";@@ -41,6 +46,11 @@ export const handle: Handle = {module: "invoicing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["invoiceId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, companyGroupId } = await requirePermissions(request,diff --git a/apps/erp/app/routes/x+/sales-order+/$orderId.tsx b/apps/erp/app/routes/x+/sales-order+/$orderId.tsxindex a88795cb55..82a1512b4c 100644--- a/apps/erp/app/routes/x+/sales-order+/$orderId.tsx+++ b/apps/erp/app/routes/x+/sales-order+/$orderId.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import {@@ -40,6 +44,11 @@ export const handle: Handle = {module: "sales"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["orderId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales",diff --git a/apps/erp/app/routes/x+/sales-return-order+/$id.tsx b/apps/erp/app/routes/x+/sales-return-order+/$id.tsxindex ceed4a5cbf..94cb960d7e 100644--- a/apps/erp/app/routes/x+/sales-return-order+/$id.tsx+++ b/apps/erp/app/routes/x+/sales-return-order+/$id.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import { getSalesReturnOrder, getSalesReturnOrderLines } from "~/modules/sales";@@ -27,6 +31,11 @@ export const handle: Handle = {module: "sales"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "sales"diff --git a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.tsx b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.tsxindex 29c6a8bd75..2f35c61026 100644--- a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.tsx+++ b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.tsx@@ -10,11 +10,15 @@ import { supportedModelTypes } from "@carbon/files/cad";import { getLogger } from "@carbon/logger";import type { JSONContent } from "@carbon/react";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import type { DragEndEvent } from "@dnd-kit/core";import { DndContext } from "@dnd-kit/core";import { msg } from "@lingui/core/macro";import type { FileObject } from "@supabase/storage-js";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams, useSubmit } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import type { SalesRFQLine } from "~/modules/sales";@@ -43,6 +47,11 @@ export const handle: Handle = {module: "sales"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["rfqId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { companyId } = await requirePermissions(request, {view: "sales"diff --git a/apps/erp/app/routes/x+/service+/$itemId.purchasing.tsx b/apps/erp/app/routes/x+/service+/$itemId.purchasing.tsxindex 45d09f8215..9a152cf1e1 100644--- a/apps/erp/app/routes/x+/service+/$itemId.purchasing.tsx+++ b/apps/erp/app/routes/x+/service+/$itemId.purchasing.tsx@@ -7,7 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { VStack } from "@carbon/react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData, useParams } from "react-router";import { useRouteData } from "~/hooks";import type { SupplierPart } from "~/modules/items";@@ -21,6 +26,11 @@ import { ItemPurchasingForm, SupplierParts } from "~/modules/items/ui/Item";import { ItemCostHistoryChart } from "~/modules/items/ui/Item/ItemCostHistoryChart";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/service+/$itemId.tsx b/apps/erp/app/routes/x+/service+/$itemId.tsxindex 511ce01536..4a3c64c9d8 100644--- a/apps/erp/app/routes/x+/service+/$itemId.tsx+++ b/apps/erp/app/routes/x+/service+/$itemId.tsx@@ -17,11 +17,15 @@ import {TabsTrigger,useRouteData} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans, useLingui } from "@lingui/react/macro";import { Suspense, useState } from "react";import { LuSearch } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Await,Outlet,@@ -57,6 +61,11 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"], search: ["methodId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/service+/_layout.tsx b/apps/erp/app/routes/x+/service+/_layout.tsxindex 17c9f47213..b833d2d257 100644--- a/apps/erp/app/routes/x+/service+/_layout.tsx+++ b/apps/erp/app/routes/x+/service+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import { getUnitOfMeasuresList } from "~/modules/items";import type { Handle } from "~/utils/handle";@@ -20,6 +25,9 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/settings+/api-keys.tsx b/apps/erp/app/routes/x+/settings+/api-keys.tsxindex 8078cc8edd..e03e7496dc 100644--- a/apps/erp/app/routes/x+/settings+/api-keys.tsx+++ b/apps/erp/app/routes/x+/settings+/api-keys.tsx@@ -5,8 +5,12 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import {@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.apiKeys};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {update: "users"diff --git a/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx b/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsxindex 74165b5385..199c00c1ff 100644--- a/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx+++ b/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx@@ -14,13 +14,23 @@ import {} from "@carbon/ee/approvals.server";import { requireFeature } from "@carbon/ee/plan.server";import { validationError, validator } from "@carbon/form";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData, useNavigate } from "react-router";import { useUrlParams } from "~/hooks";import { ApprovalRuleForm } from "~/modules/settings";import { getParams, path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings",diff --git a/apps/erp/app/routes/x+/settings+/approval-rules.tsx b/apps/erp/app/routes/x+/settings+/approval-rules.tsxindex 067a853619..1f4e525616 100644--- a/apps/erp/app/routes/x+/settings+/approval-rules.tsx+++ b/apps/erp/app/routes/x+/settings+/approval-rules.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";import { getApprovalRules } from "@carbon/ee/approvals.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import { ApprovalRules, ApprovalRulesUpgradeOverlay } from "~/modules/settings";@@ -20,6 +24,9 @@ export const handle: Handle = {to: path.to.approvalRules};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings",diff --git a/apps/erp/app/routes/x+/settings+/audit-logs.tsx b/apps/erp/app/routes/x+/settings+/audit-logs.tsxindex 79d1ac4eaa..b3870b0f65 100644--- a/apps/erp/app/routes/x+/settings+/audit-logs.tsx+++ b/apps/erp/app/routes/x+/settings+/audit-logs.tsx@@ -17,10 +17,15 @@ import {import { requireFeature } from "@carbon/ee/plan.server";import { getLogger } from "@carbon/logger";import { Button, Heading, ScrollArea, VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans } from "@lingui/react/macro";import { LuHistory } from "react-icons/lu";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Link, Outlet, redirect, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import { AuditLogSettings, AuditLogUpgradeOverlay } from "~/modules/settings";@@ -34,6 +39,9 @@ export const handle: Handle = {to: path.to.auditLog};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings"diff --git a/apps/erp/app/routes/x+/settings+/billing.tsx b/apps/erp/app/routes/x+/settings+/billing.tsxindex 84d687c63a..eb77ac2b85 100644--- a/apps/erp/app/routes/x+/settings+/billing.tsx+++ b/apps/erp/app/routes/x+/settings+/billing.tsx@@ -63,10 +63,11 @@ export async function loader({ request }: LoaderFunctionArgs) {});// Get company plan and usage data for payment section- const companyPlan = await client- .from("companyPlan")- .select(- `+ const [companyPlan, companyUsage, userToCompany] = await Promise.all([+ client+ .from("companyPlan")+ .select(+ `*,plan:planId (name,@@ -75,21 +76,16 @@ export async function loader({ request }: LoaderFunctionArgs) {aiTokensLimit)`- )- .eq("id", companyId)- .single();-- const companyUsage = await client- .from("companyUsage")- .select("*")- .eq("companyId", companyId)- .single();-- const userToCompany = await client- .from("userToCompany")- .select("userId")- .eq("companyId", companyId)- .eq("role", "employee");+ )+ .eq("id", companyId)+ .single(),+ client.from("companyUsage").select("*").eq("companyId", companyId).single(),+ client+ .from("userToCompany")+ .select("userId")+ .eq("companyId", companyId)+ .eq("role", "employee")+ ]);const userIds = userToCompany.data?.map((utc) => utc.userId) || [];diff --git a/apps/erp/app/routes/x+/settings+/companies.tsx b/apps/erp/app/routes/x+/settings+/companies.tsxindex fc94e8f77e..108ee423cc 100644--- a/apps/erp/app/routes/x+/settings+/companies.tsx+++ b/apps/erp/app/routes/x+/settings+/companies.tsx@@ -14,11 +14,14 @@ import {TabsList,TabsTrigger} from "@carbon/react";-import { isInternalEmail } from "@carbon/utils";+import { isInternalEmail, isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { useLingui } from "@lingui/react/macro";import { useCallback } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData, useNavigate } from "react-router";import { New } from "~/components";import { getSubsidiaries } from "~/modules/settings";@@ -34,6 +37,9 @@ export const handle: Handle = {to: path.to.companies};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { companyGroupId, email } = await requirePermissions(request, {view: "settings"diff --git a/apps/erp/app/routes/x+/settings+/custom-fields.$table.tsx b/apps/erp/app/routes/x+/settings+/custom-fields.$table.tsxindex ac9492617d..132e01745d 100644--- a/apps/erp/app/routes/x+/settings+/custom-fields.$table.tsx+++ b/apps/erp/app/routes/x+/settings+/custom-fields.$table.tsx@@ -5,7 +5,12 @@import { assertIsPost, error, notFound } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {data,Outlet,@@ -20,6 +25,11 @@ import { updateCustomFieldsSortOrder } from "~/modules/settings/settings.server"import { getTagsList } from "~/modules/shared";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["table"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings",diff --git a/apps/erp/app/routes/x+/settings+/custom-fields.tsx b/apps/erp/app/routes/x+/settings+/custom-fields.tsxindex 664d3722b2..8b77993090 100644--- a/apps/erp/app/routes/x+/settings+/custom-fields.tsx+++ b/apps/erp/app/routes/x+/settings+/custom-fields.tsx@@ -6,8 +6,13 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getAttributeDataTypes } from "~/modules/people";import { CustomFieldsTable, getCustomFieldsTables } from "~/modules/settings";@@ -20,6 +25,11 @@ export const handle: Handle = {to: path.to.customFields};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings",diff --git a/apps/erp/app/routes/x+/settings+/integrations.tsx b/apps/erp/app/routes/x+/settings+/integrations.tsxindex 979d42f1aa..d91ab91b6b 100644--- a/apps/erp/app/routes/x+/settings+/integrations.tsx+++ b/apps/erp/app/routes/x+/settings+/integrations.tsx@@ -11,9 +11,13 @@ import {quickInstallConnectors} from "@carbon/ee";import { toast } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { useLingui } from "@lingui/react/macro";import { useEffect } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {data,Outlet,@@ -30,6 +34,9 @@ export const config = {runtime: "nodejs"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings"diff --git a/apps/erp/app/routes/x+/settings+/printing.tsx b/apps/erp/app/routes/x+/settings+/printing.tsxindex 255d3f5b43..7c6e55d93b 100644--- a/apps/erp/app/routes/x+/settings+/printing.tsx+++ b/apps/erp/app/routes/x+/settings+/printing.tsx@@ -17,11 +17,15 @@ import {} from "@carbon/printing";import { invalidatePrinterCache } from "@carbon/printing/printing.server";import { Button, Heading, ScrollArea, VStack } from "@carbon/react";-import { labelSizes } from "@carbon/utils";+import { isUnaffectedByNavigation, labelSizes } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans } from "@lingui/react/macro";import { LuPrinter } from "react-icons/lu";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Link, Outlet, redirect, useLoaderData } from "react-router";import { getLocationsList, getWorkCentersList } from "~/modules/resources";import { getCompanySettings, printerRouteValidator } from "~/modules/settings";@@ -35,6 +39,9 @@ export const handle: Handle = {to: path.to.printingSettings};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "settings"diff --git a/apps/erp/app/routes/x+/settings+/sequences.tsx b/apps/erp/app/routes/x+/settings+/sequences.tsxindex 953f8ece91..4de9c5d87b 100644--- a/apps/erp/app/routes/x+/settings+/sequences.tsx+++ b/apps/erp/app/routes/x+/settings+/sequences.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getSequences, SequencesTable } from "~/modules/settings";import type { Handle } from "~/utils/handle";@@ -17,6 +21,11 @@ export const handle: Handle = {to: path.to.sequences};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings",diff --git a/apps/erp/app/routes/x+/settings+/serial-numbers.tsx b/apps/erp/app/routes/x+/settings+/serial-numbers.tsxindex 50723caae4..819e5c2dfd 100644--- a/apps/erp/app/routes/x+/settings+/serial-numbers.tsx+++ b/apps/erp/app/routes/x+/settings+/serial-numbers.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import {getItemSerialSequences,@@ -20,6 +24,11 @@ export const handle: Handle = {to: path.to.serialNumberSequences};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings",diff --git a/apps/erp/app/routes/x+/settings+/webhooks.tsx b/apps/erp/app/routes/x+/settings+/webhooks.tsxindex a3ca485e01..d4f8edf23c 100644--- a/apps/erp/app/routes/x+/settings+/webhooks.tsx+++ b/apps/erp/app/routes/x+/settings+/webhooks.tsx@@ -5,8 +5,12 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import { getConfig, getWebhooks } from "~/modules/settings";@@ -23,6 +27,11 @@ export const handle: Handle = {to: path.to.webhooks};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings"diff --git a/apps/erp/app/routes/x+/shipment+/$shipmentId.tsx b/apps/erp/app/routes/x+/shipment+/$shipmentId.tsxindex e95cc56577..3171654bc8 100644--- a/apps/erp/app/routes/x+/shipment+/$shipmentId.tsx+++ b/apps/erp/app/routes/x+/shipment+/$shipmentId.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import {getShipment,@@ -26,6 +30,11 @@ export const handle: Handle = {module: "inventory"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["shipmentId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/stock-transfer+/$id.tsx b/apps/erp/app/routes/x+/stock-transfer+/$id.tsxindex 5825654205..5b6625efac 100644--- a/apps/erp/app/routes/x+/stock-transfer+/$id.tsx+++ b/apps/erp/app/routes/x+/stock-transfer+/$id.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import type { JSONContent } from "@carbon/react";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData, useParams } from "react-router";import { PanelProvider } from "~/components/Layout";import { getStockTransfer, getStockTransferLines } from "~/modules/inventory";@@ -26,6 +30,11 @@ export const handle: Handle = {module: "inventory"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/supplier+/$supplierId.bank-accounts.tsx b/apps/erp/app/routes/x+/supplier+/$supplierId.bank-accounts.tsxindex 0e6e87f9d2..64f3b2edcd 100644--- a/apps/erp/app/routes/x+/supplier+/$supplierId.bank-accounts.tsx+++ b/apps/erp/app/routes/x+/supplier+/$supplierId.bank-accounts.tsx@@ -5,12 +5,21 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData } from "react-router";import { getSupplierBankAccounts } from "~/modules/purchasing";import SupplierBankAccounts from "~/modules/purchasing/ui/Supplier/SupplierBankAccounts";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["supplierId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "accounting"diff --git a/apps/erp/app/routes/x+/supplier+/$supplierId.contacts.tsx b/apps/erp/app/routes/x+/supplier+/$supplierId.contacts.tsxindex 1079b3fbbf..423f6fa34a 100644--- a/apps/erp/app/routes/x+/supplier+/$supplierId.contacts.tsx+++ b/apps/erp/app/routes/x+/supplier+/$supplierId.contacts.tsx@@ -5,12 +5,21 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData } from "react-router";import { getSupplierContacts } from "~/modules/purchasing";import SupplierContacts from "~/modules/purchasing/ui/Supplier/SupplierContacts";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["supplierId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/supplier+/$supplierId.locations.tsx b/apps/erp/app/routes/x+/supplier+/$supplierId.locations.tsxindex 64aaf04825..94adf75a96 100644--- a/apps/erp/app/routes/x+/supplier+/$supplierId.locations.tsx+++ b/apps/erp/app/routes/x+/supplier+/$supplierId.locations.tsx@@ -5,12 +5,21 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData } from "react-router";import { getSupplierLocations } from "~/modules/purchasing";import SupplierLocations from "~/modules/purchasing/ui/Supplier/SupplierLocations";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["supplierId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/supplier+/$supplierId.processes.tsx b/apps/erp/app/routes/x+/supplier+/$supplierId.processes.tsxindex 13f3f0a2f1..75ed8a3604 100644--- a/apps/erp/app/routes/x+/supplier+/$supplierId.processes.tsx+++ b/apps/erp/app/routes/x+/supplier+/$supplierId.processes.tsx@@ -5,12 +5,21 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getSupplierProcessesBySupplier } from "~/modules/purchasing";import SupplierProcesses from "~/modules/purchasing/ui/Supplier/SupplierProcesses";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["supplierId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/supplier+/$supplierId.tsx b/apps/erp/app/routes/x+/supplier+/$supplierId.tsxindex ed243b0632..c8b8dbe4cd 100644--- a/apps/erp/app/routes/x+/supplier+/$supplierId.tsx+++ b/apps/erp/app/routes/x+/supplier+/$supplierId.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect } from "react-router";import {getSupplier,@@ -30,6 +34,11 @@ export const handle: Handle = {module: "purchasing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["supplierId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/supplier+/_layout.tsx b/apps/erp/app/routes/x+/supplier+/_layout.tsxindex c5e45ffe40..4b01df4640 100644--- a/apps/erp/app/routes/x+/supplier+/_layout.tsx+++ b/apps/erp/app/routes/x+/supplier+/_layout.tsx@@ -4,8 +4,13 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import { getShippingTermsList } from "~/modules/inventory";import { getSupplierTypes } from "~/modules/purchasing";@@ -22,6 +27,9 @@ export const handle: Handle = {module: "purchasing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/supplier-quote+/$id.tsx b/apps/erp/app/routes/x+/supplier-quote+/$id.tsxindex 36d43e506c..03062c574f 100644--- a/apps/erp/app/routes/x+/supplier-quote+/$id.tsx+++ b/apps/erp/app/routes/x+/supplier-quote+/$id.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";import { getCurrencyByCode, getExchangeRate } from "~/modules/accounting";@@ -38,6 +42,11 @@ export const handle: Handle = {module: "purchasing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { companyId, companyGroupId } = await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/supplier-quote+/_layout.tsx b/apps/erp/app/routes/x+/supplier-quote+/_layout.tsxindex 632db1b788..c0563a8f14 100644--- a/apps/erp/app/routes/x+/supplier-quote+/_layout.tsx+++ b/apps/erp/app/routes/x+/supplier-quote+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -19,6 +24,9 @@ export const handle: Handle = {module: "purchasing"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {view: "purchasing"diff --git a/apps/erp/app/routes/x+/templates+/$type.tsx b/apps/erp/app/routes/x+/templates+/$type.tsxindex bb8bfb2a0f..6a9c986cfa 100644--- a/apps/erp/app/routes/x+/templates+/$type.tsx+++ b/apps/erp/app/routes/x+/templates+/$type.tsx@@ -18,7 +18,12 @@ import {} from "@carbon/documents/template";import { validationError, validator } from "@carbon/form";import type { JSONContent } from "@carbon/react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, useLoaderData } from "react-router";import { DocumentTemplateEditor } from "~/components/DocumentTemplateEditor";import { usePermissions } from "~/hooks";@@ -42,6 +47,11 @@ export const handle: Handle = {breadcrumb: (params: { type?: string }) => getDocumentLabel(params.type ?? "")};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["type"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "settings",diff --git a/apps/erp/app/routes/x+/tool+/$itemId.purchasing.$supplierPartId.tsx b/apps/erp/app/routes/x+/tool+/$itemId.purchasing.$supplierPartId.tsxindex aedff16bc1..e202b7858a 100644--- a/apps/erp/app/routes/x+/tool+/$itemId.purchasing.$supplierPartId.tsx+++ b/apps/erp/app/routes/x+/tool+/$itemId.purchasing.$supplierPartId.tsx@@ -7,7 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validator } from "@carbon/form";import { useRouteData } from "@carbon/react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { redirect, useLoaderData, useNavigate, useParams } from "react-router";import type { ToolSummary } from "~/modules/items";import { supplierPartValidator, upsertSupplierPart } from "~/modules/items";@@ -16,6 +21,11 @@ import { getDatabaseClient } from "~/services/database.server";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId", "supplierPartId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/tool+/$itemId.purchasing.tsx b/apps/erp/app/routes/x+/tool+/$itemId.purchasing.tsxindex 6ba5595e1f..7f7bad08f3 100644--- a/apps/erp/app/routes/x+/tool+/$itemId.purchasing.tsx+++ b/apps/erp/app/routes/x+/tool+/$itemId.purchasing.tsx@@ -7,8 +7,13 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { Suspense } from "react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";+import type {+ ActionFunctionArgs,+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Await, redirect, useLoaderData, useParams } from "react-router";import { useRouteData } from "~/hooks";import { getBatchProperties } from "~/modules/inventory";@@ -24,6 +29,11 @@ import { ItemPurchasingForm, SupplierParts } from "~/modules/items/ui/Item";import { ItemCostHistoryChart } from "~/modules/items/ui/Item/ItemCostHistoryChart";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/tool+/$itemId.tsx b/apps/erp/app/routes/x+/tool+/$itemId.tsxindex 0e8921370e..90f48539b7 100644--- a/apps/erp/app/routes/x+/tool+/$itemId.tsx+++ b/apps/erp/app/routes/x+/tool+/$itemId.tsx@@ -17,11 +17,15 @@ import {TabsTrigger,useRouteData} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { Trans, useLingui } from "@lingui/react/macro";import { Suspense, useState } from "react";import { LuSearch } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Await,Outlet,@@ -67,6 +71,11 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["itemId"], search: ["methodId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts",diff --git a/apps/erp/app/routes/x+/tool+/_layout.tsx b/apps/erp/app/routes/x+/tool+/_layout.tsxindex 07d8e52b9d..05d5e3fde6 100644--- a/apps/erp/app/routes/x+/tool+/_layout.tsx+++ b/apps/erp/app/routes/x+/tool+/_layout.tsx@@ -3,8 +3,13 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { requirePermissions } from "@carbon/auth/auth.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs, MetaFunction } from "react-router";+import type {+ LoaderFunctionArgs,+ MetaFunction,+ ShouldRevalidateFunction+} from "react-router";import { Outlet } from "react-router";import { getUnitOfMeasuresList } from "~/modules/items";import { getLocationsList } from "~/modules/resources";@@ -21,6 +26,9 @@ export const handle: Handle = {module: "items"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args) ? false : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "parts"diff --git a/apps/erp/app/routes/x+/training+/$id.tsx b/apps/erp/app/routes/x+/training+/$id.tsxindex b37a3d4193..9b37739376 100644--- a/apps/erp/app/routes/x+/training+/$id.tsx+++ b/apps/erp/app/routes/x+/training+/$id.tsx@@ -9,10 +9,14 @@ import { getLogger } from "@carbon/logger";import type { JSONContent } from "@carbon/react";import { generateHTML, Input, useDebounce } from "@carbon/react";import { Editor } from "@carbon/react/Editor";+import { isUnaffectedByNavigation } from "@carbon/utils";import { getLocalTimeZone, today } from "@internationalized/date";import { msg } from "@lingui/core/macro";import { useState } from "react";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import {Outlet,redirect,@@ -43,6 +47,11 @@ export const handle: Handle = {module: "resources"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["id"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "resources",diff --git a/apps/erp/app/routes/x+/users+/customers.tsx b/apps/erp/app/routes/x+/users+/customers.tsxindex f5ff792f21..524351ac19 100644--- a/apps/erp/app/routes/x+/users+/customers.tsx+++ b/apps/erp/app/routes/x+/users+/customers.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getCustomerTypes } from "~/modules/sales";import {@@ -24,6 +28,11 @@ export const handle: Handle = {to: path.to.customerAccounts};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "users",diff --git a/apps/erp/app/routes/x+/users+/employee-types.tsx b/apps/erp/app/routes/x+/users+/employee-types.tsxindex f04c0883ff..5c58c46a7f 100644--- a/apps/erp/app/routes/x+/users+/employee-types.tsx+++ b/apps/erp/app/routes/x+/users+/employee-types.tsx@@ -4,8 +4,12 @@import { requirePermissions } from "@carbon/auth/auth.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { usePlanGate } from "~/hooks/usePlanGate";import {@@ -22,6 +26,11 @@ export const handle: Handle = {to: path.to.employeeTypes};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "users",diff --git a/apps/erp/app/routes/x+/users+/employees.tsx b/apps/erp/app/routes/x+/users+/employees.tsxindex fbcf28b3a0..2f8f483662 100644--- a/apps/erp/app/routes/x+/users+/employees.tsx+++ b/apps/erp/app/routes/x+/users+/employees.tsx@@ -7,8 +7,12 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import {EmployeesTable,@@ -26,6 +30,11 @@ export const handle: Handle = {to: path.to.employeeAccounts};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "users",diff --git a/apps/erp/app/routes/x+/users+/groups.tsx b/apps/erp/app/routes/x+/users+/groups.tsxindex 444dca9e93..76c16cb84c 100644--- a/apps/erp/app/routes/x+/users+/groups.tsx+++ b/apps/erp/app/routes/x+/users+/groups.tsx@@ -6,9 +6,13 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { arrayToTree } from "performant-array-to-tree";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { data, Outlet, useLoaderData } from "react-router";import type { Group } from "~/modules/users";import { GroupsTable, getGroups } from "~/modules/users";@@ -21,6 +25,11 @@ export const handle: Handle = {to: path.to.groups};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "users",diff --git a/apps/erp/app/routes/x+/users+/operators.tsx b/apps/erp/app/routes/x+/users+/operators.tsxindex ad2d353f59..05ce3d3901 100644--- a/apps/erp/app/routes/x+/users+/operators.tsx+++ b/apps/erp/app/routes/x+/users+/operators.tsx@@ -6,6 +6,7 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { Checkbox, MenuIcon, MenuItem } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";import { useLingui } from "@lingui/react/macro";import type { ColumnDef } from "@tanstack/react-table";@@ -17,7 +18,10 @@ import {LuUser,LuUserCheck} from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData, useNavigate } from "react-router";import { EmployeeAvatar, New, Table } from "~/components";import { Enumerable } from "~/components/Enumerable";@@ -36,6 +40,11 @@ export const handle: Handle = {to: path.to.operators};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "users",diff --git a/apps/erp/app/routes/x+/users+/suppliers.tsx b/apps/erp/app/routes/x+/users+/suppliers.tsxindex b914696b78..cc69f00ceb 100644--- a/apps/erp/app/routes/x+/users+/suppliers.tsx+++ b/apps/erp/app/routes/x+/users+/suppliers.tsx@@ -6,8 +6,12 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { VStack } from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useLoaderData } from "react-router";import { getSupplierTypes } from "~/modules/purchasing";import {@@ -24,6 +28,11 @@ export const handle: Handle = {to: path.to.supplierAccounts};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "users",diff --git a/apps/erp/app/routes/x+/warehouse-transfer+/$transferId.tsx b/apps/erp/app/routes/x+/warehouse-transfer+/$transferId.tsxindex 8f305f181f..4dca5d7eca 100644--- a/apps/erp/app/routes/x+/warehouse-transfer+/$transferId.tsx+++ b/apps/erp/app/routes/x+/warehouse-transfer+/$transferId.tsx@@ -5,8 +5,12 @@import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";+import { isUnaffectedByNavigation } from "@carbon/utils";import { msg } from "@lingui/core/macro";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, redirect, useParams } from "react-router";import {getWarehouseTransfer,@@ -23,6 +27,11 @@ export const handle: Handle = {module: "inventory"};+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["transferId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {view: "inventory"diff --git a/apps/erp/app/routes/x+/workflows+/runs.$runId.tsx b/apps/erp/app/routes/x+/workflows+/runs.$runId.tsxindex b5719751a1..ccc64572af 100644--- a/apps/erp/app/routes/x+/workflows+/runs.$runId.tsx+++ b/apps/erp/app/routes/x+/workflows+/runs.$runId.tsx@@ -41,12 +41,14 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { runId } = params;if (!runId) throw new Error("runId is not found");- const runResult = await getWorkflowRun(client, runId, companyId);+ // One row past the cap tells us it truncated without a second COUNT query.+ const [runResult, stepsResult] = await Promise.all([+ getWorkflowRun(client, runId, companyId),+ getWorkflowRunSteps(client, runId, companyId)+ ]);const run = runResult.data;if (!run) throw new Error("Run not found");- // One row past the cap tells us it truncated without a second COUNT query.- const stepsResult = await getWorkflowRunSteps(client, runId, companyId);const allSteps = stepsResult.data ?? [];const truncated = allSteps.length > MAX_RUN_STEPS;const steps = truncated ? allSteps.slice(0, MAX_RUN_STEPS) : allSteps;diff --git a/apps/erp/app/routes/x+/workflows+/runs.tsx b/apps/erp/app/routes/x+/workflows+/runs.tsxindex 2d17b8f3d7..e1bb0ac1ef 100644--- a/apps/erp/app/routes/x+/workflows+/runs.tsx+++ b/apps/erp/app/routes/x+/workflows+/runs.tsx@@ -5,13 +5,22 @@import { requirePermissions } from "@carbon/auth/auth.server";import { requireFeature } from "@carbon/ee/plan.server";import { VStack } from "@carbon/react";-import type { LoaderFunctionArgs } from "react-router";+import { isUnaffectedByNavigation } from "@carbon/utils";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Outlet, useLoaderData } from "react-router";import { getWorkflowRuns } from "~/modules/workflows";import WorkflowRunsTable from "~/modules/workflows/ui/Runs/WorkflowRunsTable";import { path } from "~/utils/path";import { getGenericQueryFilters } from "~/utils/query";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { search: "all" })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {view: "workflows",diff --git a/apps/erp/app/utils/pagination.test.ts b/apps/erp/app/utils/pagination.test.tsnew file mode 100644index 0000000000..66527b05b0--- /dev/null+++ b/apps/erp/app/utils/pagination.test.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.++import { describe, expect, it, vi } from "vitest";++// The @carbon/auth barrel does not load under vitest.+vi.mock("@carbon/auth", () => ({ parseNumberFromUrlParam: vi.fn() }));++const { pageBounds } = await import("./pagination");++describe("pageBounds", () => {+ const page = (count: number, offset: number, rowsOnPage: number) =>+ pageBounds({ count, offset, pageSize: 100, rowsOnPage });++ it("ends on a short page or where an exact count says the list stops", () => {+ expect(page(5000, 300, 20).canNextPage).toBe(false);+ expect(page(200, 100, 100).canNextPage).toBe(false);+ });++ it("does not trust an estimate that equals the rows seen", () => {+ expect(page(1500, 1400, 100).canNextPage).toBe(true);+ });++ it("keeps going past a low estimate while pages come back full", () => {+ expect(page(300, 300, 100)).toEqual({ canNextPage: true, count: 400 });+ });+});diff --git a/apps/erp/app/utils/pagination.ts b/apps/erp/app/utils/pagination.tsindex b3dce78537..7ed594034a 100644--- a/apps/erp/app/utils/pagination.ts+++ b/apps/erp/app/utils/pagination.ts@@ -18,3 +18,23 @@ export function getPageSize(params: URLSearchParams): number {export function getPageOffset(params: URLSearchParams): number {return Math.max(0, parseNumberFromUrlParam(params, "offset", 0));}++// PostgREST's `estimated` count is exact up to max-rows (config.toml) and a+// planner estimate above it.+const MAX_EXACT_COUNT = 1000;++// An estimate can run low, so past the exact range the rows returned decide+// whether a next page exists.+export function pageBounds(args: {+ count: number;+ offset: number;+ pageSize: number;+ rowsOnPage: number;+}) {+ const seen = args.offset + args.rowsOnPage;+ const atExactEnd = args.count <= MAX_EXACT_COUNT && seen === args.count;+ return {+ canNextPage: args.rowsOnPage >= args.pageSize && !atExactEnd,+ count: Math.max(args.count, seen)+ };+}diff --git a/apps/erp/app/utils/query.ts b/apps/erp/app/utils/query.tsindex 98379b8364..2fa5700dfb 100644--- a/apps/erp/app/utils/query.ts+++ b/apps/erp/app/utils/query.ts@@ -8,8 +8,9 @@ import type { GenericSchema } from "@supabase/supabase-js/dist/module/lib/types"import { getPageOffset, getPageSize } from "./pagination";/**- * Count mode for the paged list endpoints backed by the big multi-join views- * (`parts`, `materials`, `salesOrders`, `purchaseOrders`, the invoice views…).+ * Count mode for every paged list endpoint — any query that goes through+ * `setGenericQueryFilters`. Counts that drive logic rather than a pager+ * (`head: true`, limits, "is this in use?") stay `exact`.** PostgREST implements `exact` as `COUNT(*) OVER ()`, which makes Postgres* materialize the entire filtered result set purely to produce a total — so@@ -20,7 +21,8 @@ import { getPageOffset, getPageSize } from "./pagination";* the estimate for result sets far larger than any page a user is reading. The* totals stay accurate at the sizes where being off by a few would be visible.*- * These endpoints also pair it with an explicit `*_LIST_COLUMNS` constant rather+ * The big multi-join views (`parts`, `materials`, `salesOrders`,+ * `purchaseOrders`, the invoice views…) also pair it with an explicit `*_LIST_COLUMNS` constant rather* than `select("*")`, for the same reason: naming the columns lets Postgres* prune the views' unreferenced computed columns instead of materializing them* per row. Adding a column to one of those tables means adding it to thediff --git a/apps/mes/app/routes/x+/_layout.tsx b/apps/mes/app/routes/x+/_layout.tsxindex a871e51318..3930f64927 100644--- a/apps/mes/app/routes/x+/_layout.tsx+++ b/apps/mes/app/routes/x+/_layout.tsx@@ -42,8 +42,8 @@ import {import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";import {Edition,- isSearchParamOnlyNavigation,- requiresItarEntityCertification+ requiresItarEntityCertification,+ SHELL_MAX_AGE_MS} from "@carbon/utils";import { Trans } from "@lingui/react/macro";import posthog from "posthog-js";@@ -82,9 +82,12 @@ import {import { getOpenClockEntry } from "~/services/people.service";import { ERP_URL, MES_URL, path } from "~/utils/path";+// Set from the component when loader data arrives, not in shouldRevalidate:+// link prefetching calls that too.+let shellLoadedAt = Date.now();+export const shouldRevalidate: ShouldRevalidateFunction = ({currentUrl,- nextUrl,formMethod,formAction,defaultShouldRevalidate@@ -108,16 +111,10 @@ export const shouldRevalidate: ShouldRevalidateFunction = ({return true;}- // This loader is the app shell: 9 queries plus an auth round-trip. Without- // this it re-ran on every filter, sort and page click, none of which can- // change anything it returns.- // NOTE: `useRevalidator().revalidate()` — how the realtime hooks refresh —- // also looks like a same-pathname GET, so the shell does not re-run for- // realtime events either. Leaf loaders still refresh, which is the intent.- // Shell data that must react to a realtime change needs an explicit case- // above.- if (isSearchParamOnlyNavigation({ currentUrl, nextUrl, formMethod })) {- return false;+ // Only a mutation can change what the shell returns, so a GET re-runs it+ // only once the data has aged out — that covers out-of-band changes.+ if (!formMethod || formMethod === "GET") {+ return Date.now() - shellLoadedAt > SHELL_MAX_AGE_MS;}return defaultShouldRevalidate;@@ -132,26 +129,6 @@ export async function loader({ request, context }: LoaderFunctionArgs) {// share a client between requestsconst client = getCarbon(accessToken);- // parallelize the requests- const [companies, user] = await Promise.all([- getCompanies(client, userId),- getUser(client, userId)- ]);-- if (user.error || !user.data) {- throw await destroyAuthSession(request);- }-- const company = companies.data?.find((c) => c.companyId === companyId);- if (!company) {- // A company-less authenticated user (e.g. an enterprise first-run user who- // hasn't onboarded) has no MES to enter — MES doesn't host onboarding.- // Send them to a terminal screen that links to ERP onboarding, not into- // accountSettings (an ERP /x route that would itself bounce a no-company- // user, i.e. a redirect loop).- throw redirect(path.to.setupRequired);- }-// Get the location and console state from middleware contextconst ctx = context.get(userContext);const locationId = ctx?.locationId;@@ -162,6 +139,9 @@ export async function loader({ request, context }: LoaderFunctionArgs) {const serviceRole = getCarbonServiceRole();let [+ companies,+ user,+ activeMaintenanceCount,companyPlan,locations,activeEvents,@@ -170,6 +150,9 @@ export async function loader({ request, context }: LoaderFunctionArgs) {locationEmployees,printerRoutes] = await Promise.all([+ getCompanies(client, userId),+ getUser(client, userId),+ getActiveMaintenanceEventsCount(client, locationId),getStripeCustomerByCompanyId(companyId, userId),getLocationsByCompany(client, companyId),getActiveJobCount(client, {@@ -195,6 +178,20 @@ export async function loader({ request, context }: LoaderFunctionArgs) {getPrinterRoutes(serviceRole, companyId)]);+ if (user.error || !user.data) {+ throw await destroyAuthSession(request);+ }++ const company = companies.data?.find((c) => c.companyId === companyId);+ if (!company) {+ // A company-less authenticated user (e.g. an enterprise first-run user who+ // hasn't onboarded) has no MES to enter — MES doesn't host onboarding.+ // Send them to a terminal screen that links to ERP onboarding, not into+ // accountSettings (an ERP /x route that would itself bounce a no-company+ // user, i.e. a redirect loop).+ throw redirect(path.to.setupRequired);+ }+const locationEmployeeIds =locationEmployees.data?.map((e: { id: string }) => e.id) ?? [];const timeCardEnabled = companySettings.data?.timeCardEnabled ?? false;@@ -234,12 +231,6 @@ export async function loader({ request, context }: LoaderFunctionArgs) {? !(await userHasVerifiedTotpFactor(userId)): false;- // Get active maintenance count after we have the location- const activeMaintenanceCount = await getActiveMaintenanceEventsCount(- client,- locationId- );-// ITAR gate — only queried in controlled environments. `entityRequired` is// false for Carbon staff: the Rider binds the customer's own organization, so// it is not ours to accept and the pending block would strand us behind a@@ -324,6 +315,7 @@ export async function loader({ request, context }: LoaderFunctionArgs) {}export default function AuthenticatedRoute() {+ const loaderData = useLoaderData<typeof loader>();const {session,activeEvents,@@ -346,7 +338,11 @@ export default function AuthenticatedRoute() {itarCertification,mfaEnrollmentRequired,sessionTimeout- } = useLoaderData<typeof loader>();+ } = loaderData;+ // biome-ignore lint/correctness/useExhaustiveDependencies: runs each time the loader does+ useEffect(() => {+ shellLoadedAt = Date.now();+ }, [loaderData]);const navigate = useNavigate();diff --git a/apps/mes/app/routes/x+/dispatch.$dispatchId.tsx b/apps/mes/app/routes/x+/dispatch.$dispatchId.tsxindex 155a462d20..bc171974c7 100644--- a/apps/mes/app/routes/x+/dispatch.$dispatchId.tsx+++ b/apps/mes/app/routes/x+/dispatch.$dispatchId.tsx@@ -21,12 +21,16 @@ import {useDisclosure,VStack} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { Trans, useLingui } from "@lingui/react/macro";import { useMemo } from "react";import { BsExclamationSquareFill } from "react-icons/bs";import { FaCheck, FaPause, FaPlay } from "react-icons/fa6";import { LuArrowLeft, LuCheck, LuCirclePlus, LuX } from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Link, useFetcher, useLoaderData } from "react-router";import { z } from "zod";import { HighPriorityIcon } from "~/assets/icons/HighPriorityIcon";@@ -52,6 +56,11 @@ import type {import { useItems } from "~/stores";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["dispatchId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {});const { dispatchId } = params;diff --git a/apps/mes/app/routes/x+/picking.$pickingListId.tracked.$lineId.tsx b/apps/mes/app/routes/x+/picking.$pickingListId.tracked.$lineId.tsxindex 697dbd8774..7b3046de70 100644--- a/apps/mes/app/routes/x+/picking.$pickingListId.tracked.$lineId.tsx+++ b/apps/mes/app/routes/x+/picking.$pickingListId.tracked.$lineId.tsx@@ -51,18 +51,22 @@ export async function loader({ request, params }: LoaderFunctionArgs) {(line.item as { itemTrackingType: string } | null)?.itemTrackingType ??"Batch";- const entities = locationId- ? await getAvailableTrackedEntities(client, {- itemId: line.itemId,- companyId,- locationId,- excludeLineside: true,- excludeAllocated: true,- excludeLineId: lineId- })- : { data: [] };-- const settings = await getCompanySettings(client, companyId);+ const [entities, settings, defaultOrder] = await Promise.all([+ locationId+ ? getAvailableTrackedEntities(client, {+ itemId: line.itemId,+ companyId,+ locationId,+ excludeLineside: true,+ excludeAllocated: true,+ excludeLineId: lineId+ })+ : { data: [] },+ getCompanySettings(client, companyId),+ locationId+ ? getPickOrder(client, { itemId: line.itemId, locationId, companyId })+ : ("Default" as const)+ ]);const shelfLife = (settings.data?.inventoryShelfLife ?? {}) as {nearExpiryWarningDays?: number | null;expiredEntityPolicy?: "Warn" | "Block" | "BlockWithOverride";@@ -77,13 +81,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {),nearExpiryWarningDays: shelfLife.nearExpiryWarningDays ?? 0,expiredEntityPolicy: shelfLife.expiredEntityPolicy ?? "Warn",- defaultOrder: locationId- ? await getPickOrder(client, {- itemId: line.itemId,- locationId,- companyId- })- : "Default"+ defaultOrder};}diff --git a/apps/mes/app/routes/x+/picking.$pickingListId.tsx b/apps/mes/app/routes/x+/picking.$pickingListId.tsxindex a6f6365aa2..8855a8c5a4 100644--- a/apps/mes/app/routes/x+/picking.$pickingListId.tsx+++ b/apps/mes/app/routes/x+/picking.$pickingListId.tsx@@ -41,6 +41,7 @@ import {toast,VStack} from "@carbon/react";+import { isUnaffectedByNavigation } from "@carbon/utils";import { Trans } from "@lingui/react/macro";import { Suspense, useEffect, useMemo, useState } from "react";import {@@ -52,7 +53,10 @@ import {LuTriangleAlert,LuUndo2} from "react-icons/lu";-import type { LoaderFunctionArgs } from "react-router";+import type {+ LoaderFunctionArgs,+ ShouldRevalidateFunction+} from "react-router";import { Await, useFetcher, useLoaderData } from "react-router";import { Enumerable } from "~/components/Enumerable";import ItemThumbnail from "~/components/ItemThumbnail";@@ -66,6 +70,11 @@ import { getPickingListForExecution } from "~/services/picking.service";import { useItems } from "~/stores";import { path } from "~/utils/path";+export const shouldRevalidate: ShouldRevalidateFunction = (args) =>+ isUnaffectedByNavigation(args, { params: ["pickingListId"] })+ ? false+ : args.defaultShouldRevalidate;+export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {});const pickingListId = params.pickingListId!;diff --git a/packages/ee/src/plan.server.test.ts b/packages/ee/src/plan.server.test.tsindex 197945ab8f..ff0d25ef58 100644--- a/packages/ee/src/plan.server.test.ts+++ b/packages/ee/src/plan.server.test.ts@@ -12,6 +12,8 @@ const serviceRoleFrom = vi.hoisted(() =>})));const isCarbonOwnedCompany = vi.hoisted(() => vi.fn());+const redisGet = vi.hoisted(() => vi.fn());+const redisSet = vi.hoisted(() => vi.fn());vi.mock("@carbon/auth", () => ({CarbonEdition: "cloud",@@ -23,6 +25,10 @@ vi.mock("@carbon/auth/client.server", () => ({}));vi.mock("@carbon/auth/company.server", () => ({ isCarbonOwnedCompany }));vi.mock("@carbon/auth/session.server", () => ({ flash: vi.fn() }));+vi.mock("@carbon/kv", () => ({ redis: { get: redisGet, set: redisSet } }));+vi.mock("@carbon/logger/middleware.server", () => ({+ oncePerRead: (_key: string, compute: () => unknown) => compute()+}));vi.mock("@carbon/logger", () => ({getLogger: () => ({error: vi.fn(),@@ -53,6 +59,7 @@ describe("plan gate reads companyPlan via service role", () => {beforeEach(() => {vi.clearAllMocks();isCarbonOwnedCompany.mockResolvedValue(false);+ redisGet.mockResolvedValue(null);});it("grants a PARTNER-* company MCP even when the caller's client cannot see the plan row", async () => {@@ -91,3 +98,35 @@ describe("plan gate reads companyPlan via service role", () => {expect(allowed).toBe(false);});});++describe("plan gate cache", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ isCarbonOwnedCompany.mockResolvedValue(false);+ redisGet.mockResolvedValue(null);+ });++ it("answers from Redis without reading companyPlan", async () => {+ redisGet.mockResolvedValue("PARTNER-33");++ const allowed = await companyHasFeature(+ rlsBlockedClient() as never,+ "company-1",+ { feature: "MCP" }+ );++ expect(allowed).toBe(true);+ expect(redisGet).toHaveBeenCalledWith("companyPlan:company-1");+ expect(serviceRoleFrom).not.toHaveBeenCalled();+ });++ it("does not cache a missing plan row", async () => {+ serviceRoleMaybeSingle.mockResolvedValue({ data: null, error: null });++ await companyHasFeature(rlsBlockedClient() as never, "company-3", {+ feature: "MCP"+ });++ expect(redisSet).not.toHaveBeenCalled();+ });+});diff --git a/packages/ee/src/plan.server.ts b/packages/ee/src/plan.server.tsindex 366bc86881..4f41eecd05 100644--- a/packages/ee/src/plan.server.ts+++ b/packages/ee/src/plan.server.ts@@ -7,8 +7,15 @@ import { getCarbonServiceRole } from "@carbon/auth/client.server";import { isCarbonOwnedCompany } from "@carbon/auth/company.server";import { flash } from "@carbon/auth/session.server";import type { Database } from "@carbon/database";+import { redis } from "@carbon/kv";import { getLogger } from "@carbon/logger";-import { Edition, normalizePlanId, Plan } from "@carbon/utils";+import { oncePerRead } from "@carbon/logger/middleware.server";+import {+ companyPlanCacheKey,+ Edition,+ normalizePlanId,+ Plan+} from "@carbon/utils";import type { SupabaseClient } from "@supabase/supabase-js";import { redirect } from "react-router";import {@@ -41,7 +48,22 @@ function isBypassCompany(companyId: string): boolean {// rules) off — fail-open. Callers are UI gates and evaluators that should not 500// on a transient blip, so log rather than throw; the signal is what was missing// when this silently disabled rules.-async function readCompanyPlan(companyId: string): Promise<string | null> {+//+// Cached in Redis and cleared by the Stripe sync; the TTL covers writes that+// don't clear it. A missing row is never cached.+const PLAN_CACHE_TTL_SECONDS = 60;++function readCompanyPlan(companyId: string): Promise<string | null> {+ return oncePerRead(`companyPlan:${companyId}`, () =>+ loadCompanyPlan(companyId)+ );+}++async function loadCompanyPlan(companyId: string): Promise<string | null> {+ const cacheKey = companyPlanCacheKey(companyId);+ const cached = await redis.get(cacheKey);+ if (cached) return cached;+const { data, error: planError } = await getCarbonServiceRole().from("companyPlan").select("planId")@@ -52,6 +74,10 @@ async function readCompanyPlan(companyId: string): Promise<string | null> {logger.error("getCompanyPlan failed", { companyId, error: planError });}+ if (data?.planId) {+ await redis.set(cacheKey, data.planId, "EX", PLAN_CACHE_TTL_SECONDS);+ }+return data?.planId ?? null;}diff --git a/packages/stripe/src/stripe.server.ts b/packages/stripe/src/stripe.server.tsindex 408927c4c4..ecafde04b2 100644--- a/packages/stripe/src/stripe.server.ts+++ b/packages/stripe/src/stripe.server.ts@@ -15,7 +15,7 @@ import {import { redis } from "@carbon/kv";import { trigger } from "@carbon/lib/trigger";import { getLogger } from "@carbon/logger";-import { Edition, Plan } from "@carbon/utils";+import { companyPlanCacheKey, Edition, Plan } from "@carbon/utils";import type { SupabaseClient } from "@supabase/supabase-js";import { Stripe } from "stripe";import { z } from "zod";@@ -619,6 +619,7 @@ export async function syncStripeDataToKV(if (companyPlan.error) {log.error("Failed to upsert company plan", { error: companyPlan.error });}+ await redis.del(companyPlanCacheKey(companyId));} else {log.error("no company id, skipping company plan upsert");}diff --git a/packages/utils/AGENTS.md b/packages/utils/AGENTS.mdindex 890b37397f..a3bab7121f 100644--- a/packages/utils/AGENTS.md+++ b/packages/utils/AGENTS.md@@ -47,7 +47,7 @@ pnpm --filter @carbon/utils typecheck| `precision` | The whole numeric-precision API, re-exported from the edge-runtime module: `SCALE`, `EPSILON`, `RoundingMode`, `round`, `distributeRoundingResidual`, `scrapAllowance`, `applyRate`, `deriveRate`, `isBalanced`, `assertBalanced` || `format` | The ONLY place display/input digit counts are chosen: `moneyFormatOptions` (settlement — the currency's decimals are floor AND ceiling), `rateFormatOptions` (per-unit RATE — those decimals are only the floor, ceiling is `SCALE`), the `PERCENT_FORMAT` / `PERCENT_POINTS_FORMAT` / `SCALE_FORMAT` constants, `cldrCurrencyDecimals`, their `format*` helpers, and `INPUT_FORMAT` / `INPUT_STEP` for editable fields. Call sites pick a KIND, never a digit count || `string` | Slugify, truncate, camelCase/titleCase conversions |-| `revalidate` | `isSearchParamOnlyNavigation` — shared by both apps' shell `shouldRevalidate` |+| `revalidate` | `shouldRevalidate` predicates: `isSearchParamOnlyNavigation` (root loaders), `isUnaffectedByNavigation` (detail layouts — names the route/search params the loader reads) || `status` | Status resolution, status color mapping || `rules` | Rule engine: condition AST, the shared `Operator` vocabulary, JIT-compiled evaluator + surfaces for storage rules and sales rules || `rule-filters` | Item scoping for broadcast rules (`ItemFilter`, `ruleAppliesToItem`, `toItemFilter`) — family-neutral, split out of `rules.ts` |diff --git a/packages/utils/src/revalidate.test.ts b/packages/utils/src/revalidate.test.tsindex 2d01cf0858..00f6400d7e 100644--- a/packages/utils/src/revalidate.test.ts+++ b/packages/utils/src/revalidate.test.ts@@ -3,7 +3,10 @@// including ports, remain AGPLv3; serving them over a network requires releasing their source.import { describe, expect, it } from "vitest";-import { isSearchParamOnlyNavigation } from "./revalidate";+import {+ isSearchParamOnlyNavigation,+ isUnaffectedByNavigation+} from "./revalidate";const url = (href: string) => new URL(href, "https://erp.test");@@ -71,3 +74,62 @@ describe("isSearchParamOnlyNavigation", () => {).toBe(true);});});++describe("isUnaffectedByNavigation", () => {+ const nav = (+ from: string,+ to: string,+ itemIds: [string, string] = ["a", "a"],+ formMethod?: string+ ) =>+ isUnaffectedByNavigation(+ {+ currentUrl: url(from),+ nextUrl: url(to),+ currentParams: { itemId: itemIds[0] },+ nextParams: { itemId: itemIds[1] },+ formMethod+ },+ { params: ["itemId"], search: ["methodId"] }+ );++ it("is true when nothing the loader reads changed", () => {+ expect(nav("/x/part/a/details", "/x/part/a/planning")).toBe(true);+ expect(nav("/x/part/a/make/m1", "/x/part/a/make/m2?materialId=x")).toBe(+ true+ );+ });++ it("is false when a param or search param the loader reads changed", () => {+ expect(nav("/x/part/a/details", "/x/part/b/details", ["a", "b"])).toBe(+ false+ );+ expect(nav("/x/part/a/details", "/x/part/a/details?methodId=m")).toBe(+ false+ );+ });++ it("is false for a revalidation or a mutation", () => {+ expect(nav("/x/part/a/details", "/x/part/a/details")).toBe(false);+ expect(+ nav("/x/part/a/details", "/x/part/a/planning", ["a", "a"], "POST")+ ).toBe(false);+ });++ it('compares the whole query string with search "all"', () => {+ const list = (from: string, to: string) =>+ isUnaffectedByNavigation(+ {+ currentUrl: url(from),+ nextUrl: url(to),+ currentParams: {},+ nextParams: {}+ },+ { search: "all" }+ );+ expect(list("/x/items/parts?sort=a", "/x/items/parts/new?sort=a")).toBe(+ true+ );+ expect(list("/x/items/parts?sort=a", "/x/items/parts/new")).toBe(false);+ });+});diff --git a/packages/utils/src/revalidate.ts b/packages/utils/src/revalidate.tsindex 564cf7ce9a..21acae1a04 100644--- a/packages/utils/src/revalidate.ts+++ b/packages/utils/src/revalidate.ts@@ -28,3 +28,40 @@ export function isSearchParamOnlyNavigation({if (formMethod && formMethod !== "GET") return false;return currentUrl.pathname === nextUrl.pathname;}++/**+ * True when a GET navigation left the route params and search params a layout+ * loader reads unchanged (`search: "all"` for one that reads the whole query+ * string). Single fetch otherwise re-runs every matched loader on every+ * navigation. Mutations and `useRevalidator().revalidate()` are never+ * "unaffected".+ */+export function isUnaffectedByNavigation(+ {+ currentUrl,+ nextUrl,+ currentParams,+ nextParams,+ formMethod+ }: {+ currentUrl: URL;+ nextUrl: URL;+ currentParams: Record<string, string | undefined>;+ nextParams: Record<string, string | undefined>;+ formMethod?: string;+ },+ reads: { params?: string[]; search?: string[] | "all" } = {}+) {+ if (formMethod && formMethod !== "GET") return false;+ if (currentUrl.href === nextUrl.href) return false;+ const { params = [], search = [] } = reads;+ if (!params.every((key) => currentParams[key] === nextParams[key])) {+ return false;+ }+ if (search === "all") return currentUrl.search === nextUrl.search;+ return search.every(+ (key) => currentUrl.searchParams.get(key) === nextUrl.searchParams.get(key)+ );+}++export const SHELL_MAX_AGE_MS = 5 * 60 * 1000;diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.tsindex b162c45533..e1b518196b 100644--- a/packages/utils/src/types.ts+++ b/packages/utils/src/types.ts@@ -26,6 +26,9 @@ export enum Plan {// DB stores partner tiers as `PARTNER-300/400/500` etc. Collapse them onto// `Plan.Partner` so plan-gate checks (`requirement.includes(plan)`) match.+export const companyPlanCacheKey = (companyId: string) =>+ `companyPlan:${companyId}`;+export function normalizePlanId(planId: string | null | undefined): Plan {if (!planId) return Plan.Unknown;if (planId.startsWith("PARTNER")) return Plan.Partner;