Skip to content

Commit fc37337

Browse files
committed
fix(app): memory leak with platform fetch for events
1 parent 80220ce commit fc37337

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/app/src/context/global-sdk.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
1212
const platform = usePlatform()
1313
const abort = new AbortController()
1414

15+
const auth = (() => {
16+
if (typeof window === "undefined") return
17+
const password = window.__OPENCODE__?.serverPassword
18+
if (!password) return
19+
return {
20+
Authorization: `Basic ${btoa(`opencode:${password}`)}`,
21+
}
22+
})()
23+
1524
const eventSdk = createOpencodeClient({
1625
baseUrl: server.url,
1726
signal: abort.signal,
18-
fetch: platform.fetch,
27+
headers: auth,
1928
})
2029
const emitter = createGlobalEmitter<{
2130
[key: string]: Event

packages/opencode/src/server/server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export namespace Server {
7878
})
7979
})
8080
.use((c, next) => {
81+
// Allow CORS preflight requests to succeed without auth.
82+
// Browser clients sending Authorization headers will preflight with OPTIONS.
83+
if (c.req.method === "OPTIONS") return next()
8184
const password = Flag.OPENCODE_SERVER_PASSWORD
8285
if (!password) return next()
8386
const username = Flag.OPENCODE_SERVER_USERNAME ?? "opencode"
@@ -107,7 +110,12 @@ export namespace Server {
107110

108111
if (input.startsWith("http://localhost:")) return input
109112
if (input.startsWith("http://127.0.0.1:")) return input
110-
if (input === "tauri://localhost" || input === "http://tauri.localhost") return input
113+
if (
114+
input === "tauri://localhost" ||
115+
input === "http://tauri.localhost" ||
116+
input === "https://tauri.localhost"
117+
)
118+
return input
111119

112120
// *.opencode.ai (https only, adjust if needed)
113121
if (/^https:\/\/([a-z0-9-]+\.)*opencode\.ai$/.test(input)) {

0 commit comments

Comments
 (0)