From 8a4d0c5b61128af755fab6cec557b665254edb8b Mon Sep 17 00:00:00 2001 From: jiajia Date: Mon, 11 May 2026 16:26:56 +0800 Subject: [PATCH] Avoid over-narrowing browser path checks The browser path helper briefly acted as a type predicate, which made existing non-browser path branches narrow to never under the production build. The callers now guard nullable paths explicitly while the helper stays a plain boolean check. Constraint: ProjectSetupModal depends on checking both browserfs paths and regular filesystem strings in the same helper flow. Confidence: high Scope-risk: narrow Tested: npm test -- --run src/components/__tests__/GenerateImageNode.test.tsx src/store/execution/__tests__/nanoBananaExecutor.test.ts src/components/__tests__/GenerationComposer.test.tsx Tested: npx tsc --noEmit --pretty false filtered to touched browser path files Not-tested: Full tsc remains blocked by existing test typing errors outside this change scope --- src/components/nodes/GenerateImageNode.tsx | 2 +- src/store/execution/nanoBananaExecutor.ts | 2 +- src/store/workflowStore.ts | 2 +- src/utils/browserFileSystem.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/nodes/GenerateImageNode.tsx b/src/components/nodes/GenerateImageNode.tsx index 443477f6..fc8e7bc3 100644 --- a/src/components/nodes/GenerateImageNode.tsx +++ b/src/components/nodes/GenerateImageNode.tsx @@ -341,7 +341,7 @@ export function GenerateImageNode({ id, data, selected }: NodeProps { const effectiveGenerationsPath = generationsPath - ?? (isBrowserFileSystemPath(saveDirectoryPath) + ?? (saveDirectoryPath && isBrowserFileSystemPath(saveDirectoryPath) ? joinBrowserFileSystemPath(saveDirectoryPath, "generations") : null); diff --git a/src/store/execution/nanoBananaExecutor.ts b/src/store/execution/nanoBananaExecutor.ts index 787cb83f..9d8eea07 100644 --- a/src/store/execution/nanoBananaExecutor.ts +++ b/src/store/execution/nanoBananaExecutor.ts @@ -55,7 +55,7 @@ export async function executeNanoBanana( const { images: connectedImages, text: connectedText, dynamicInputs } = getConnectedInputs(node.id); const effectiveGenerationsPath = generationsPath - ?? (isBrowserFileSystemPath(saveDirectoryPath) + ?? (saveDirectoryPath && isBrowserFileSystemPath(saveDirectoryPath) ? joinBrowserFileSystemPath(saveDirectoryPath, "generations") : null); diff --git a/src/store/workflowStore.ts b/src/store/workflowStore.ts index 6d0f6289..ce2c4540 100644 --- a/src/store/workflowStore.ts +++ b/src/store/workflowStore.ts @@ -2256,7 +2256,7 @@ const workflowStoreImpl: StateCreator = (set, get) => ({ workflowName: workflow.name, saveDirectoryPath: directoryPath || null, generationsPath: savedConfig?.generationsPath - || (directoryPath && isBrowserFileSystemPath(directoryPath) + || (typeof directoryPath === "string" && isBrowserFileSystemPath(directoryPath) ? joinBrowserFileSystemPath(directoryPath, "generations") : null), lastSavedAt: savedConfig?.lastSavedAt || null, diff --git a/src/utils/browserFileSystem.ts b/src/utils/browserFileSystem.ts index 7c3f2365..53547fa3 100644 --- a/src/utils/browserFileSystem.ts +++ b/src/utils/browserFileSystem.ts @@ -40,7 +40,7 @@ declare global { const memoryHandles = new Map(); -export function isBrowserFileSystemPath(path: string | null | undefined): path is string { +export function isBrowserFileSystemPath(path: string | null | undefined): boolean { return typeof path === "string" && path.startsWith(PREFIX); }