Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix lazy import localforage

Brad Barbin472ba67650e9
diff --git a/apps/carbon/app/components/RealtimeDataProvider.tsx b/apps/carbon/app/components/RealtimeDataProvider.tsx
index 5247ade9bd..ba81724e72 100644
--- a/apps/carbon/app/components/RealtimeDataProvider.tsx
+++ b/apps/carbon/app/components/RealtimeDataProvider.tsx
@@ -2,7 +2,6 @@
import { useCarbon } from "@carbon/auth";
import type { RealtimeChannel } from "@supabase/supabase-js";
-import idb from "localforage";
import { useEffect, useRef } from "react";
import { useUser } from "~/hooks";
import { useCustomers, useItems, usePeople, useSuppliers } from "~/stores";
@@ -28,6 +27,7 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
const [, setPeople] = usePeople();
const hydrate = async () => {
+ const idb = (await import("localforage")).default;
if (!hydratedFromIdb) {
hydratedFromIdb = true;
@@ -94,6 +94,11 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
// @ts-ignore
people.data?.filter((p) => !p.email?.includes("@carbonos.dev")) ?? []
);
+
+ idb.setItem("items", items.data);
+ idb.setItem("suppliers", suppliers.data);
+ idb.setItem("customers", customers.data);
+ idb.setItem("people", people.data);
};
const channelRef = useRef<RealtimeChannel | null>(null);
diff --git a/packages/remix/src/hooks/useNanoStore.ts b/packages/remix/src/hooks/useNanoStore.ts
index 480fccabd9..6312aeecc8 100644
--- a/packages/remix/src/hooks/useNanoStore.ts
+++ b/packages/remix/src/hooks/useNanoStore.ts
@@ -1,5 +1,4 @@
import { useStore } from "@nanostores/react";
-import idb from "localforage";
import { type WritableAtom } from "nanostores";
import { useCallback } from "react";
@@ -10,13 +9,11 @@ export function useNanoStore<T>(atom: WritableAtom<T>, idbKey?: string) {
(value: T | ((current: T) => T), initial = false) => {
if (typeof value === "function") {
atom.set((value as (current: T) => T)(atom.get()));
- if (idbKey && !initial) idb.setItem(idbKey, atom.get());
} else {
atom.set(value);
- if (idbKey && !initial) idb.setItem(idbKey, value);
}
},
- [atom, idbKey]
+ [atom]
);
return [value, set] as const;