summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-02-10 11:30:54 -0600
committerAdam <[email protected]>2026-02-10 11:30:58 -0600
commitd1f5b9e911617e793957c416879d88bf9f665e33 (patch)
tree2582b0870efac58cd276aecc901259c1ed2cd7b4
parent284b00ff23bd15964ad74b136e12427b7f70962c (diff)
downloadopencode-d1f5b9e911617e793957c416879d88bf9f665e33.tar.gz
opencode-d1f5b9e911617e793957c416879d88bf9f665e33.zip
fix(app): memory leak with event fetch
-rw-r--r--packages/app/src/context/global-sdk.tsx27
1 files changed, 26 insertions, 1 deletions
diff --git a/packages/app/src/context/global-sdk.tsx b/packages/app/src/context/global-sdk.tsx
index 0cd4f6c99..e96d9c46f 100644
--- a/packages/app/src/context/global-sdk.tsx
+++ b/packages/app/src/context/global-sdk.tsx
@@ -12,10 +12,35 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
const platform = usePlatform()
const abort = new AbortController()
+ // Prefer the WebView fetch implementation for streaming responses.
+ // @tauri-apps/plugin-http 2.5.x has known issues with streaming/cancellation that can
+ // retain native resources in the Rust process.
+ const base = platform.platform === "desktop" ? globalThis.fetch : (platform.fetch ?? globalThis.fetch)
+
+ const eventFetch = Object.assign(
+ (input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => {
+ const password = (globalThis as { __OPENCODE__?: { serverPassword?: string } }).__OPENCODE__?.serverPassword
+ const header = password ? `Basic ${btoa(`opencode:${password}`)}` : undefined
+
+ const headers = new Headers(input instanceof Request ? input.headers : undefined)
+ if (init?.headers) {
+ new Headers(init.headers).forEach((value, key) => {
+ headers.set(key, value)
+ })
+ }
+ if (header) headers.set("Authorization", header)
+
+ return base(input, { ...(init ?? {}), headers })
+ },
+ {
+ preconnect: (...args: Parameters<typeof fetch.preconnect>) => (base as any).preconnect?.(...args),
+ },
+ ) satisfies typeof fetch
+
const eventSdk = createOpencodeClient({
baseUrl: server.url,
signal: abort.signal,
- fetch: platform.fetch,
+ fetch: eventFetch,
})
const emitter = createGlobalEmitter<{
[key: string]: Event