From 58cfc30cd744aefba66eaedf14ee54faa22d7e72 Mon Sep 17 00:00:00 2001 From: Gerhard Scheikl Date: Fri, 8 May 2026 14:41:48 +0200 Subject: [PATCH] fix(build): extract STORED_LOGO_SENTINEL to non-server module Vite/React Router refused to bundle the client because app/routes/app.settings.tsx imported the constant from a .server file and used it inside the route component (not just loader/action), so it could not be tree-shaken out. Move the sentinel to logoCache.constants.ts, re-export from logoCache.server.ts for backwards compatibility, and import the constant from constants in the route while keeping the server-only functions (deleteStoredLogo, storeUploadedLogo) imported from .server (they are only referenced inside the action and get tree-shaken correctly). --- app/routes/app.settings.tsx | 2 +- app/services/invoice/logoCache.constants.ts | 6 ++++++ app/services/invoice/logoCache.server.ts | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 app/services/invoice/logoCache.constants.ts diff --git a/app/routes/app.settings.tsx b/app/routes/app.settings.tsx index b8ca3bf..208c777 100644 --- a/app/routes/app.settings.tsx +++ b/app/routes/app.settings.tsx @@ -8,8 +8,8 @@ import { isValidIban, normaliseIban, } from "../services/invoice/validation"; +import { STORED_LOGO_SENTINEL } from "../services/invoice/logoCache.constants"; import { - STORED_LOGO_SENTINEL, deleteStoredLogo, storeUploadedLogo, } from "../services/invoice/logoCache.server"; diff --git a/app/services/invoice/logoCache.constants.ts b/app/services/invoice/logoCache.constants.ts new file mode 100644 index 0000000..c1762e2 --- /dev/null +++ b/app/services/invoice/logoCache.constants.ts @@ -0,0 +1,6 @@ +/** + * Shared (client + server safe) constants for the logo cache. + * Kept in a non-`.server` module so route components can import them + * without React Router pulling server-only code into the client bundle. + */ +export const STORED_LOGO_SENTINEL = "stored://shop-logo"; diff --git a/app/services/invoice/logoCache.server.ts b/app/services/invoice/logoCache.server.ts index 99b0dae..0f8a170 100644 --- a/app/services/invoice/logoCache.server.ts +++ b/app/services/invoice/logoCache.server.ts @@ -1,4 +1,5 @@ import db from "../../db.server"; +import { STORED_LOGO_SENTINEL } from "./logoCache.constants"; const MAX_BYTES = 5 * 1024 * 1024; // 5 MB cap const STALE_AFTER_MS = 24 * 60 * 60 * 1000; // re-fetch once a day at most @@ -7,8 +8,11 @@ const STALE_AFTER_MS = 24 * 60 * 60 * 1000; // re-fetch once a day at most * Sentinel value stored in `ShopSettings.logoUrl` when the logo was uploaded * directly through the settings UI (rather than fetched from a remote URL). * The actual bytes live in `LogoCache` for that shop. + * + * Re-exported from `logoCache.constants` so existing server-side imports keep + * working; new client/route imports should use `logoCache.constants` directly. */ -export const STORED_LOGO_SENTINEL = "stored://shop-logo"; +export { STORED_LOGO_SENTINEL }; /** * Returns a `data:` URL for the shop's logo bytes, fetching from the