Skip to content

Commit 852431f

Browse files
committed
Handle empty file paths in composer fallback
1 parent 8811906 commit 852431f

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ export const ChatComposer = memo(
15561556
nonImageFiles.map(async (file) => {
15571557
try {
15581558
const resolvedPath = await localApi?.shell.getPathForFile(file);
1559-
return formatComposerFileReference(resolvedPath ?? file.name);
1559+
return formatComposerFileReference(resolvedPath || file.name);
15601560
} catch {
15611561
return formatComposerFileReference(file.name);
15621562
}

‎apps/web/src/localApi.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,18 @@ describe("wsApi", () => {
538538
await expect(api.shell.getPathForFile(file)).resolves.toBeNull();
539539
});
540540

541+
it("normalizes empty dropped-file paths from the desktop bridge to null", async () => {
542+
const getPathForFile = vi.fn().mockReturnValue("");
543+
getWindowForTest().desktopBridge = makeDesktopBridge({ getPathForFile });
544+
545+
const { createLocalApi } = await import("./localApi");
546+
const api = createLocalApi(rpcClientMock as never);
547+
const file = new File(['{"hello":"world"}'], "input.json", { type: "application/json" });
548+
549+
await expect(api.shell.getPathForFile(file)).resolves.toBeNull();
550+
expect(getPathForFile).toHaveBeenCalledWith(file);
551+
});
552+
541553
it("falls back to the browser context menu helper when the desktop bridge is missing", async () => {
542554
showContextMenuFallbackMock.mockResolvedValue("rename");
543555
const { createLocalApi } = await import("./localApi");

‎apps/web/src/localApi.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export function createLocalApi(rpcClient: WsRpcClient): LocalApi {
5353

5454
window.open(url, "_blank", "noopener,noreferrer");
5555
},
56-
getPathForFile: async (file) => window.desktopBridge?.getPathForFile(file) ?? null,
56+
getPathForFile: async (file) => {
57+
const resolvedPath = window.desktopBridge?.getPathForFile(file);
58+
return resolvedPath || null;
59+
},
5760
},
5861
contextMenu: {
5962
show: async <T extends string>(

0 commit comments

Comments
 (0)