From 4e7990a460284716c32ca565bcebfdf3eacb62fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E9=AB=98?= Date: Thu, 12 Nov 2026 15:34:05 +0800 Subject: [PATCH] fix(studio): show a small spinner while applying fonts --- .../editor/propertyPanelFont.test.tsx | 37 +++++++++++++++++++ .../components/editor/propertyPanelFont.tsx | 17 +++++++-- studio/tests/e2e/local-fonts.mjs | 16 ++++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/studio/src/components/editor/propertyPanelFont.test.tsx b/studio/src/components/editor/propertyPanelFont.test.tsx index bd3e371c6..d65e5a221 100644 --- a/studio/src/components/editor/propertyPanelFont.test.tsx +++ b/studio/src/components/editor/propertyPanelFont.test.tsx @@ -215,6 +215,43 @@ describe("FontFamilyField session font lists", () => { }); describe("FontFamilyField installed fonts", () => { + it.each([[true, true], [false, true], [true, false], [false, false]])("shows a small loading indicator through font import and save (flat: %s, saved: %s)", async (flat, saved) => { + vi.resetModules(); + const { FontFamilyField } = await import("./propertyPanelFont"); + let imported!: (fonts: Array<{ family: string; path: string; url: string }>) => void; + let finish!: () => void, fail!: (reason: Error) => void; + const onImportFonts = vi.fn(() => new Promise>(resolve => { imported = resolve; })); + const onCommit = vi.fn(() => new Promise((resolve, reject) => { finish = resolve; fail = reject; })); + const log = vi.spyOn(console, "error").mockImplementation(() => {}); + const host = document.createElement("div"); + document.body.append(host); + const root = createRoot(host); + try { + await act(async () => root.render()); + await act(async () => new Promise(resolve => setTimeout(resolve, 10))); + const trigger = host.querySelector("button")!; + await act(async () => trigger.click()); + const option = Array.from(document.querySelectorAll("[data-font-option-index]")).find(button => button.textContent?.includes("Menlo"))!; + await act(async () => option.click()); + expect(trigger.disabled).toBe(true); + expect(trigger.getAttribute("aria-busy")).toBe("true"); + expect(trigger.querySelector('[role="status"]')?.getAttribute("aria-label")).toBe("Loading"); + expect(trigger.querySelector('[data-remix-icon="loader-4-line"]')).not.toBeNull(); + expect(onCommit).not.toHaveBeenCalled(); + await act(async () => imported([{ family: "Menlo", path: "font.ttf", url: "/font.ttf" }])); + expect(onCommit).toHaveBeenCalledOnce(); + expect(trigger.querySelector('[role="status"]')).not.toBeNull(); + await act(async () => saved ? finish() : fail(new Error("Save failed"))); + expect(trigger.disabled).toBe(false); + expect(trigger.getAttribute("aria-busy")).toBe("false"); + expect(trigger.querySelector('[role="status"]')).toBeNull(); + if (!saved) { + expect(trigger.textContent).toContain("Arial"); + expect(document.body.textContent).toContain('Couldn\'t import "Menlo"'); + } + } finally { act(() => root.unmount()); log.mockRestore(); } + }); + it.each([true, false])("uses the server font file without browser font access (available: %s)", async (available) => { vi.resetModules(); const { FontFamilyField } = await import("./propertyPanelFont"); diff --git a/studio/src/components/editor/propertyPanelFont.tsx b/studio/src/components/editor/propertyPanelFont.tsx index a1f4dc53f..ecdbff843 100644 --- a/studio/src/components/editor/propertyPanelFont.tsx +++ b/studio/src/components/editor/propertyPanelFont.tsx @@ -17,6 +17,7 @@ import { useTrackDesignInput } from "../../contexts/DesignPanelInputContext"; import { runWhenInputIdle } from "./overlayFrameLoop"; import { studioApiFetch } from "../../utils/studioApiFetch"; import { useStudioShellContextOptional } from "../../contexts/StudioContext"; +import { RemixIcon } from "../../icons/RemixIcons"; /* ------------------------------------------------------------------ */ /* Font helper functions */ @@ -426,6 +427,12 @@ export function FontFamilyField({ ); + const fontLoadingIndicator = importingFonts ? ( + + + + ) : null; + if (flat) { return (
@@ -434,6 +441,7 @@ export function FontFamilyField({ type="button" data-flat-font-trigger="true" disabled={disabled || importingFonts} + aria-busy={importingFonts} className="flex items-center gap-1.5 disabled:cursor-not-allowed" > {currentFamily} - - + } )}
); @@ -462,6 +470,7 @@ export function FontFamilyField({ {renderPicker()} ); diff --git a/studio/tests/e2e/local-fonts.mjs b/studio/tests/e2e/local-fonts.mjs index c011d7d52..a67a11e41 100644 --- a/studio/tests/e2e/local-fonts.mjs +++ b/studio/tests/e2e/local-fonts.mjs @@ -157,6 +157,22 @@ try { results.pickerHeight = pickerHeight; page.off('request', holdCatalog); await page.setRequestInterception(false); + await page.setRequestInterception(true); + const holdImport = request => { + if (!new URL(request.url()).pathname.endsWith('/fonts/import')) void request.continue(); + }; + page.on('request', holdImport); + const firstImport = page.waitForRequest(request => new URL(request.url()).pathname.endsWith('/fonts/import')); + await choose(results.fonts[0].family); + const importing = await firstImport; + await page.waitForSelector('[data-flat-font-trigger][aria-busy="true"] [role="status"]'); + await capture('font-applying.png'); + await importing.continue(); + page.off('request', holdImport); + await page.setRequestInterception(false); + await applied(results.fonts[0].family); + assert.equal(await page.$('[data-flat-font-trigger] [role="status"]'), null); + results.fontApplyingIndicator = true; for (const font of results.fonts) { await choose(font.family); await applied(font.family); await page.waitForFunction(family => document.querySelector('hyperframes-player').shadowRoot.querySelector('iframe').contentDocument.querySelector('#title').style.fontFamily.includes(family), {}, font.family);