From 7374076506ee337c620b87b458c822fd86427fac Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 25 Sep 2025 19:39:12 -0400 Subject: [PATCH] fix nx singleton mangling (#851) --- frontend/libs/api/src/lib/UsersApi.ts | 6 ++-- .../src/lib/config/StorytellerApiHostStore.ts | 30 ++++++++++++++++--- frontend/libs/api/vite.config.ts | 11 +++++++ .../promptbox/src/lib/PromptBoxImage.tsx | 2 +- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/frontend/libs/api/src/lib/UsersApi.ts b/frontend/libs/api/src/lib/UsersApi.ts index bbed26ebd4..72ce5e9aaf 100644 --- a/frontend/libs/api/src/lib/UsersApi.ts +++ b/frontend/libs/api/src/lib/UsersApi.ts @@ -98,15 +98,15 @@ export class UsersApi extends ApiManager { usernameOrEmail: string; password: string; }): Promise> { - console.log("Logging in with usernameOrEmail:", usernameOrEmail); + console.log("libs/api - Logging in with usernameOrEmail:", usernameOrEmail); const endpoint = `${this.getApiSchemeAndHost()}/v1/login`; + console.log("libs/api - Login endpoint", endpoint); const body = { username_or_email: usernameOrEmail, password: password, }; try { - console.log("calling auth fetch") const response = await this.authFetch< { username_or_email: string; password: string }, { @@ -119,8 +119,6 @@ export class UsersApi extends ApiManager { method: "POST", body: body, }); - console.log(response) - console.log("Auth fetch response!!! above") return { success: response.success, data: response.success diff --git a/frontend/libs/api/src/lib/config/StorytellerApiHostStore.ts b/frontend/libs/api/src/lib/config/StorytellerApiHostStore.ts index 7855e911f7..c90da8cb2f 100644 --- a/frontend/libs/api/src/lib/config/StorytellerApiHostStore.ts +++ b/frontend/libs/api/src/lib/config/StorytellerApiHostStore.ts @@ -1,8 +1,14 @@ // Artcraft / Storyteller API backend const DEFAULT_API_HOST = "https://api.storyteller.ai"; +// NB(bt,2025-09-25): 'nx' is creating multiple copies of the library with name +// mangling, so the singleton pattern fails to resolve to a single instance. +(window as any).STORYTELLER_API_HOST_STORE = undefined; + export class StorytellerApiHostStore { - private static instance: StorytellerApiHostStore; + // NB(bt,2025-09-25): 'nx' is creating multiple copies of the library with name + // mangling, so the singleton pattern fails to resolve to a single instance. + // private static instance: StorytellerApiHostStore; /** * The scheme and host of the API. @@ -11,17 +17,29 @@ export class StorytellerApiHostStore { */ private apiSchemeAndHost: string; + // NB(bt,2025-09-25): 'nx' is creating multiple copies of the library with name + // mangling, so the singleton pattern fails to resolve to a single instance. + // public static getInstance(): StorytellerApiHostStore { + // if (StorytellerApiHostStore.instance !== undefined) { + // return StorytellerApiHostStore.instance; + // } + // const instance = new StorytellerApiHostStore(DEFAULT_API_HOST); + // StorytellerApiHostStore.instance = instance; + // return instance; + // } + public static getInstance(): StorytellerApiHostStore { - if (StorytellerApiHostStore.instance !== undefined) { - return StorytellerApiHostStore.instance; + if ((window as any).STORYTELLER_API_HOST_STORE !== undefined) { + return (window as any).STORYTELLER_API_HOST_STORE; } const instance = new StorytellerApiHostStore(DEFAULT_API_HOST); - StorytellerApiHostStore.instance = instance; + (window as any).STORYTELLER_API_HOST_STORE = instance; return instance; } /** Get the API scheme and host. */ public getApiSchemeAndHost(): string { + console.debug("StorytellerApiHostStore.getApiSchemeAndHost()", this.apiSchemeAndHost, this.constructor.name); return this.apiSchemeAndHost; } @@ -30,14 +48,18 @@ export class StorytellerApiHostStore { * This is used to sync with Tauri for enabling easier development. */ public setApiSchemeAndHost(apiSchemeAndHost: string) { + console.debug("StorytellerApiHostStore.setApiSchemeAndHost()", apiSchemeAndHost, this.constructor.name); + // TODO(bt,2025-07-06): Actually parse URL. if (!apiSchemeAndHost.startsWith("http://") && !apiSchemeAndHost.startsWith("https://")) { throw new Error(`Scheme not included in URL: ${apiSchemeAndHost}`); } + const FINAL_VALID_SLASH = "https://".lastIndexOf("/"); if (apiSchemeAndHost.lastIndexOf("/") > FINAL_VALID_SLASH) { throw new Error(`Path components should not be included in URL: ${apiSchemeAndHost}`); } + this.apiSchemeAndHost = apiSchemeAndHost; } diff --git a/frontend/libs/api/vite.config.ts b/frontend/libs/api/vite.config.ts index 60cc978f0f..d438324592 100644 --- a/frontend/libs/api/vite.config.ts +++ b/frontend/libs/api/vite.config.ts @@ -33,6 +33,17 @@ export default defineConfig(() => ({ // External packages that should not be bundled into your library. external: [] }, + // NB(bt,2025-09-25): This mangling config doesn't seem like it works: + //terserOptions: { + // compress: { + // keep_classnames: true, + // keep_fnames: true, + // }, + // mangle: { + // keep_classnames: true, + // keep_fnames: true, + // } + //}, }, test: { watch: false, diff --git a/frontend/libs/components/promptbox/src/lib/PromptBoxImage.tsx b/frontend/libs/components/promptbox/src/lib/PromptBoxImage.tsx index c6729de157..3fa6c4793e 100644 --- a/frontend/libs/components/promptbox/src/lib/PromptBoxImage.tsx +++ b/frontend/libs/components/promptbox/src/lib/PromptBoxImage.tsx @@ -64,7 +64,7 @@ export const PromptBoxImage = ({ }: PromptBoxImageProps) => { useSignals(); - console.log("Selected model:", selectedModel); + console.debug("Selected model:", selectedModel); useEffect(() => { if (imageMediaId && url) {