Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(web): ignore late Tauri HTTP abort cleanup failures (#7897)

teocb11c8e55f94
diff --git a/apps/web/patches/@tauri-apps%[email protected] b/apps/web/patches/@tauri-apps%[email protected]
new file mode 100644
index 0000000000..dbefa88419
--- /dev/null
+++ b/apps/web/patches/@tauri-apps%[email protected]
@@ -0,0 +1,68 @@
+diff --git a/dist-js/index.cjs b/dist-js/index.cjs
+index f1bba4502af349efbde8b94ac1b1773a490f4836..18b6c78e7102523d557430eaae94d839fcef0cb0 100644
+--- a/dist-js/index.cjs
++++ b/dist-js/index.cjs
+@@ -103,21 +103,24 @@ async function fetch(input, init) {
+ danger
+ }
+ });
+- const abort = () => core.invoke('plugin:http|fetch_cancel', { rid });
++ const abort = () => core.invoke('plugin:http|fetch_cancel', { rid }).catch(() => { });
+ // Optimistically check for abort signal
+ // and avoid doing any work after doing intial work on the Rust side
+ if (signal?.aborted) {
+- // we don't care about the result of this proimse
+- // eslint-disable-next-line @typescript-eslint/no-floating-promises
+- abort();
++ // we don't care about the result of this promise
++ void abort();
+ throw new Error(ERROR_REQUEST_CANCELLED);
+ }
+ signal?.addEventListener('abort', () => void abort());
+ const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await core.invoke('plugin:http|fetch_send', {
+ rid
+ });
++ let bodyDropped = false;
+ const dropBody = () => {
+- return core.invoke('plugin:http|fetch_cancel_body', { rid: responseRid });
++ if (bodyDropped)
++ return Promise.resolve();
++ bodyDropped = true;
++ return core.invoke('plugin:http|fetch_cancel_body', { rid: responseRid }).catch(() => { });
+ };
+ const readChunk = async (controller) => {
+ let data;
+diff --git a/dist-js/index.js b/dist-js/index.js
+index 01f0ea49e0fe45425adcb8596f57e97a92c8c958..f38dbd4b68c3efa578cf6a8309543840a3619c77 100644
+--- a/dist-js/index.js
++++ b/dist-js/index.js
+@@ -101,21 +101,24 @@ async function fetch(input, init) {
+ danger
+ }
+ });
+- const abort = () => invoke('plugin:http|fetch_cancel', { rid });
++ const abort = () => invoke('plugin:http|fetch_cancel', { rid }).catch(() => { });
+ // Optimistically check for abort signal
+ // and avoid doing any work after doing intial work on the Rust side
+ if (signal?.aborted) {
+- // we don't care about the result of this proimse
+- // eslint-disable-next-line @typescript-eslint/no-floating-promises
+- abort();
++ // we don't care about the result of this promise
++ void abort();
+ throw new Error(ERROR_REQUEST_CANCELLED);
+ }
+ signal?.addEventListener('abort', () => void abort());
+ const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await invoke('plugin:http|fetch_send', {
+ rid
+ });
++ let bodyDropped = false;
+ const dropBody = () => {
+- return invoke('plugin:http|fetch_cancel_body', { rid: responseRid });
++ if (bodyDropped)
++ return Promise.resolve();
++ bodyDropped = true;
++ return invoke('plugin:http|fetch_cancel_body', { rid: responseRid }).catch(() => { });
+ };
+ const readChunk = async (controller) => {
+ let data;
diff --git a/apps/web/src/lib/tauri/http-plugin.test.ts b/apps/web/src/lib/tauri/http-plugin.test.ts
new file mode 100644
index 0000000000..5dcf9b72ef
--- /dev/null
+++ b/apps/web/src/lib/tauri/http-plugin.test.ts
@@ -0,0 +1,88 @@
+// @vitest-environment node
+import { fetch } from '@tauri-apps/plugin-http';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+type Args = { rid: number };
+
+/** Mirrors tauri-plugin-http's resource table: the body resource closes at
+ * end of stream, and closing an already-closed id rejects. */
+function fakeHttpBridge(body: string) {
+ const open = new Set<number>();
+ let nextRid = 0;
+ let bodySent = false;
+ const add = () => {
+ open.add(++nextRid);
+ return nextRid;
+ };
+ const requireOpen = (rid: number) => {
+ if (!open.has(rid)) throw `The resource id ${rid} is invalid.`;
+ };
+ const close = (rid: number) => {
+ requireOpen(rid);
+ open.delete(rid);
+ };
+ const commands: Record<string, (args: Args) => unknown> = {
+ 'plugin:http|fetch': () => add(),
+ 'plugin:http|fetch_cancel': ({ rid }) => requireOpen(rid),
+ 'plugin:http|fetch_send': () => ({
+ status: 200,
+ statusText: 'OK',
+ url: 'https://example.com/',
+ headers: [],
+ rid: add(),
+ }),
+ 'plugin:http|fetch_read_body': ({ rid }) => {
+ requireOpen(rid);
+ if (bodySent) {
+ close(rid);
+ return [1];
+ }
+ bodySent = true;
+ return [...new TextEncoder().encode(body), 0];
+ },
+ 'plugin:http|fetch_cancel_body': ({ rid }) => close(rid),
+ };
+ return async (cmd: string, args: Args) => commands[cmd](args);
+}
+
+let unhandled: unknown[];
+const recordUnhandled = (reason: unknown) => unhandled.push(reason);
+
+beforeEach(() => {
+ unhandled = [];
+ process.on('unhandledRejection', recordUnhandled);
+ vi.stubGlobal('window', {
+ __TAURI_INTERNALS__: { invoke: fakeHttpBridge('ok') },
+ });
+});
+
+afterEach(() => {
+ process.off('unhandledRejection', recordUnhandled);
+ vi.unstubAllGlobals();
+});
+
+describe('tauri http plugin fetch', () => {
+ it.each([
+ {
+ name: 'reading the whole body',
+ finish: async (response: Response) => {
+ expect(await response.text()).toBe('ok');
+ },
+ },
+ {
+ name: 'cancelling the body',
+ finish: (response: Response) => response.body?.cancel(),
+ },
+ ])('ignores an abort that arrives after $name', async ({ finish }) => {
+ const controller = new AbortController();
+ const response = await fetch('https://example.com/', {
+ signal: controller.signal,
+ });
+ await finish(response);
+
+ controller.abort();
+ await new Promise((resolve) => setTimeout(resolve, 0));
+
+ expect(unhandled).toEqual([]);
+ });
+});
diff --git a/bun.lock b/bun.lock
index 42d1ca1eb9..2cde92643a 100644
--- a/bun.lock
+++ b/bun.lock
@@ -542,6 +542,7 @@
"[email protected]": "apps/web/patches/[email protected]",
"@lexical/[email protected]": "apps/web/patches/@lexical%[email protected]",
"@thisbeyond/[email protected]": "apps/web/patches/@thisbeyond%[email protected]",
+ "@tauri-apps/[email protected]": "apps/web/patches/@tauri-apps%[email protected]",
},
"overrides": {
"@kobalte/core": "0.13.11",
diff --git a/nix-support/node_modules-hashes.json b/nix-support/node_modules-hashes.json
index 7cf66fb599..ed51ba77af 100644
--- a/nix-support/node_modules-hashes.json
+++ b/nix-support/node_modules-hashes.json
@@ -1,6 +1,6 @@
{
"nodeModules": {
- "aarch64-darwin": "sha256-9bFwe5o3iBLBrlBlRQ3hmeq0A7VjmDbsxGTjOpFnSqY=",
- "x86_64-linux": "sha256-9WeocJXG6/po7vLNPjue7JUErg1K7nJ5Q7X5yZ6XrpE="
+ "aarch64-darwin": "sha256-3wWxSfUdJGk55nicYAy/nVi+qpCKARt95wotnoByosA=",
+ "x86_64-linux": "sha256-Cynm6t+15CaXQh09cpOkwgjx5qJGVjOEiTusnyKRxIU="
}
}
diff --git a/package.json b/package.json
index 1a8474aa61..b27efc4c3f 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,8 @@
"@tanstack/[email protected]": "apps/web/patches/@tanstack%[email protected]",
"@lexical/[email protected]": "apps/web/patches/@lexical%[email protected]",
"[email protected]": "apps/web/patches/[email protected]",
- "@tanstack/[email protected]": "apps/web/patches/@tanstack%[email protected]"
+ "@tanstack/[email protected]": "apps/web/patches/@tanstack%[email protected]",
+ "@tauri-apps/[email protected]": "apps/web/patches/@tauri-apps%[email protected]"
},
"private": true,
"scripts": {