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(erp): pass STRIPE_CONNECT_ENABLED through the root loader to window.env (#1461)

Brad Barbin5089ee75ee33
diff --git a/.ai/lessons.md b/.ai/lessons.md
index 46339e8655..d01f5afd60 100644
--- a/.ai/lessons.md
+++ b/.ai/lessons.md
@@ -1141,3 +1141,13 @@ canvas hosting Radix popovers/selects.
**Rule:** A path check in the server entry silently outranks routing for everything under it. If you short-circuit a prefix, derive the exemptions from the build manifest (`build.routes`) rather than assuming the prefix stays route-free — a comment asserting "no app route" is a claim that rots the moment somebody adds one. Three false leads to skip next time this shape appears: it reproduces identically on Vercel AND `react-router-serve` (so it is not the platform); `/.foo` and `/.env` return normal 404s (so it is not dotfile handling); and `matchRoutes` against the full route table picks the RIGHT route and passes WITH the bug present (so a matcher test proves nothing). The tell was that percent-encoding the dot (`/%2Ewell-known/...`) returned `200 application/json` — `new URL().pathname` leaves the escape undecoded so `startsWith` missed, while the router decodes and matched.
**Applies to:** `apps/erp/server/app.ts`, `apps/mes/server/*`, and any request-handler wrapper that inspects `pathname` before delegating.
+
+## A browser-safe env flag isn't live until the root loader's hand-built `env` also carries it
+
+**Context:** The Stripe Connect integration card stayed "Coming soon" even with `STRIPE_SECRET_KEY` set server-side. `getBrowserEnv()` (`packages/env/src/index.ts`) already exposed `STRIPE_CONNECT_ENABLED` and the `Window.env` interface declared it, so it looked fully wired — but the browser gate `window.env?.STRIPE_CONNECT_ENABLED === "true"` still read `undefined`.
+
+**Problem:** `apps/erp/app/root.tsx`'s loader does NOT pass `getBrowserEnv()` through — it destructures specific keys and rebuilds an `env: { ... }` object by hand, and `window.env` is populated from THAT loader object on the normal render path (`const env = loaderData?.env ?? {}` → `<Document env={env}>`). The new flag was added to `getBrowserEnv()` but never added to the loader's manual list, so it was silently dropped client-side. (The ErrorBoundary path uses `getBrowserEnv()` directly, which masks the gap during casual reading.)
+
+**Rule:** Adding a browser-safe var is THREE edits, not one: the `getEnv` export, `getBrowserEnv()` + the `Window.env` interface, AND the consuming app's root-loader `env` object (destructure + literal) for every app that needs it client-side. The loader's hand-curated `env` is the real source of `window.env` on the happy path — a key present in `getBrowserEnv()` but absent there is `undefined` in the browser. When an env-driven feature is dark despite the server value being set, diff `getBrowserEnv()`'s keys against the loader's `env` object before touching anything else.
+
+**Applies to:** `apps/erp/app/root.tsx` (and `apps/mes/app/root.tsx`) loader `env` objects, `packages/env/src/index.ts` `getBrowserEnv()`, any `window.env`-gated integration/feature flag.
diff --git a/apps/erp/app/root.tsx b/apps/erp/app/root.tsx
index 1082d82108..41a38851ed 100644
--- a/apps/erp/app/root.tsx
+++ b/apps/erp/app/root.tsx
@@ -95,6 +95,7 @@ export async function loader({ request, context }: LoaderFunctionArgs) {
POSTHOG_API_HOST,
POSTHOG_PROJECT_PUBLIC_KEY,
QUICKBOOKS_CLIENT_ID,
+ STRIPE_CONNECT_ENABLED,
SUPABASE_ANON_KEY,
SUPABASE_URL,
DEFAULT_LANGUAGE,
@@ -127,6 +128,7 @@ export async function loader({ request, context }: LoaderFunctionArgs) {
POSTHOG_API_HOST,
POSTHOG_PROJECT_PUBLIC_KEY,
QUICKBOOKS_CLIENT_ID,
+ STRIPE_CONNECT_ENABLED,
SUPABASE_ANON_KEY,
SUPABASE_URL,
VERCEL_ENV,