Skip to content

AI-native design editor. Open-source Figma alternative.

fix: load fonts with request in desktop app cause OOMs (replaced with fetch)

them7d6ffde827d5e3
diff --git a/src/app/tauri/http.ts b/src/app/tauri/http.ts
index 29fefb760..eb31cfab2 100644
--- a/src/app/tauri/http.ts
+++ b/src/app/tauri/http.ts
@@ -1,4 +1,3 @@
-import type { FetchFunction } from '@/app/http/types'
export interface ProxyHttpHeader {
name: string
@@ -74,9 +73,6 @@ export interface TauriFetchOptions {
maxResponseBytes?: number
}
-export function createTauriFetch(options: TauriFetchOptions = {}): FetchFunction {
- return (input, init) => tauriFetch(input, init, options.maxResponseBytes, options.timeoutMs)
-}
export async function tauriFetch(
input: RequestInfo | URL,
@@ -84,15 +80,29 @@ export async function tauriFetch(
maxResponseBytes?: number,
timeoutMs?: number
): Promise<Response> {
+ const url = typeof input === 'string' ? input : (input instanceof URL ? input.href : input.url);
+
+ if (url.startsWith('http://ipc.localhost') || url.startsWith('https://ipc.localhost') || url.startsWith('ipc://')) {
+ return fetch(input as RequestInfo, init);
+ }
+
const request = new Request(input, init)
request.signal.throwIfAborted()
const { invoke } = await import('@tauri-apps/api/core')
request.signal.throwIfAborted()
+
+ let bodyData: Uint8Array | undefined = undefined
+ if (request.body != null) {
+ const buffer = await request.arrayBuffer()
+ request.signal.throwIfAborted()
+ bodyData = new Uint8Array(buffer)
+ }
+
const payload: ProxyHttpRequest = {
url: request.url,
method: request.method,
headers: headersToProxyHeaders(request.headers),
- body: request.body == null ? undefined : [...new Uint8Array(await request.arrayBuffer())],
+ body: bodyData ? Array.from(bodyData) : undefined,
max_response_bytes: maxResponseBytes,
follow_redirects: request.redirect === 'follow',
timeout_ms: timeoutMs
diff --git a/tests/engine/tauri/http.test.ts b/tests/engine/tauri/http.test.ts
index 453d9035b..19551b68f 100644
--- a/tests/engine/tauri/http.test.ts
+++ b/tests/engine/tauri/http.test.ts
@@ -1,7 +1,6 @@
import { afterEach, describe, expect, test } from 'bun:test'
import {
- createTauriFetch,
tauriFetch,
type ProxyHttpRequest,
type ProxyHttpResponse
@@ -56,12 +55,6 @@ describe('tauriFetch', () => {
}
})
- const response = await createTauriFetch({ timeoutMs: 15_000 })('https://example.test/check', {
- method: 'POST',
- headers: { 'content-type': 'application/json' },
- body: '{"ok":true}'
- })
-
if (!captured) throw new Error('Expected proxy_http_request to be invoked')
expect(response.status).toBe(201)
expect(response.headers.get('x-open-pencil')).toBe('ok')