Browse Source

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
feature/canvas-chatbot-copilot
jiajia 2 months ago
parent
commit
8a4d0c5b61
  1. 2
      src/components/nodes/GenerateImageNode.tsx
  2. 2
      src/store/execution/nanoBananaExecutor.ts
  3. 2
      src/store/workflowStore.ts
  4. 2
      src/utils/browserFileSystem.ts

2
src/components/nodes/GenerateImageNode.tsx

@ -341,7 +341,7 @@ export function GenerateImageNode({ id, data, selected }: NodeProps<NanoBananaNo
const loadImageById = useCallback(async (imageId: string) => { const loadImageById = useCallback(async (imageId: string) => {
const effectiveGenerationsPath = generationsPath const effectiveGenerationsPath = generationsPath
?? (isBrowserFileSystemPath(saveDirectoryPath) ?? (saveDirectoryPath && isBrowserFileSystemPath(saveDirectoryPath)
? joinBrowserFileSystemPath(saveDirectoryPath, "generations") ? joinBrowserFileSystemPath(saveDirectoryPath, "generations")
: null); : null);

2
src/store/execution/nanoBananaExecutor.ts

@ -55,7 +55,7 @@ export async function executeNanoBanana(
const { images: connectedImages, text: connectedText, dynamicInputs } = getConnectedInputs(node.id); const { images: connectedImages, text: connectedText, dynamicInputs } = getConnectedInputs(node.id);
const effectiveGenerationsPath = generationsPath const effectiveGenerationsPath = generationsPath
?? (isBrowserFileSystemPath(saveDirectoryPath) ?? (saveDirectoryPath && isBrowserFileSystemPath(saveDirectoryPath)
? joinBrowserFileSystemPath(saveDirectoryPath, "generations") ? joinBrowserFileSystemPath(saveDirectoryPath, "generations")
: null); : null);

2
src/store/workflowStore.ts

@ -2256,7 +2256,7 @@ const workflowStoreImpl: StateCreator<WorkflowStore> = (set, get) => ({
workflowName: workflow.name, workflowName: workflow.name,
saveDirectoryPath: directoryPath || null, saveDirectoryPath: directoryPath || null,
generationsPath: savedConfig?.generationsPath generationsPath: savedConfig?.generationsPath
|| (directoryPath && isBrowserFileSystemPath(directoryPath) || (typeof directoryPath === "string" && isBrowserFileSystemPath(directoryPath)
? joinBrowserFileSystemPath(directoryPath, "generations") ? joinBrowserFileSystemPath(directoryPath, "generations")
: null), : null),
lastSavedAt: savedConfig?.lastSavedAt || null, lastSavedAt: savedConfig?.lastSavedAt || null,

2
src/utils/browserFileSystem.ts

@ -40,7 +40,7 @@ declare global {
const memoryHandles = new Map<string, FileSystemDirectoryHandle>(); const memoryHandles = new Map<string, FileSystemDirectoryHandle>();
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); return typeof path === "string" && path.startsWith(PREFIX);
} }

Loading…
Cancel
Save