diff --git a/apps/ai-game-creator-shell/src/features/ui-editor/useUiEditorFontFaces.ts b/apps/ai-game-creator-shell/src/features/ui-editor/useUiEditorFontFaces.ts index c3b00de6c..0696ee745 100644 --- a/apps/ai-game-creator-shell/src/features/ui-editor/useUiEditorFontFaces.ts +++ b/apps/ai-game-creator-shell/src/features/ui-editor/useUiEditorFontFaces.ts @@ -69,6 +69,8 @@ export function useUiEditorFontFaces( for (const font of fontAssets) { void (async () => { const cssFamily = uiEditorPrivateFontFamily(font.asset_id); + let url: string | undefined; + let face: FontFace | undefined; try { if (typeof FontFace === 'undefined' || !document.fonts) { throw new Error('FontFace unavailable'); @@ -80,10 +82,10 @@ export function useUiEditorFontFaces( expectedSha256: font.content_sha256, }); if (cancelled) return; - const url = URL.createObjectURL( + url = URL.createObjectURL( new Blob([new Uint8Array(bytes)], { type: fontMimeType(font) }), ); - const face = new FontFace(cssFamily, `url(${JSON.stringify(url)})`, { + face = new FontFace(cssFamily, `url(${JSON.stringify(url)})`, { style: font.metadata.italic ? 'italic' : 'normal', weight: String(font.metadata.weight), }); @@ -99,6 +101,12 @@ export function useUiEditorFontFaces( [font.asset_id]: { cssFamily, status: 'loaded' }, })); } catch { + if (face) { + document.fonts?.delete(face); + } + if (url) { + URL.revokeObjectURL(url); + } if (!cancelled) { setStates((current) => ({ ...current,