From 10ebb98310703434eb3115665845dcad15942290 Mon Sep 17 00:00:00 2001 From: KnowSky404 Date: Sun, 1 Nov 2026 15:18:09 +0800 Subject: [PATCH 1/2] fix(ui): keep cloud operations in foreground loading --- docs/wiki/Changelog.md | 11 + docs/wiki/Changelog.zh-CN.md | 8 + e2e/gists-readonly.spec.ts | 61 ++++- e2e/ui-interactions.spec.ts | 7 +- e2e/workspace-reset.spec.ts | 9 + e2e/workspace-v2.spec.ts | 258 +++++++++++++++++- src/lib/components/ActionButton.svelte | 4 +- src/lib/components/Dialog.svelte | 18 +- .../WorkspaceOperationProgress.svelte | 26 ++ src/lib/i18n.ts | 2 + src/lib/stores/app.ts | 7 +- src/lib/workspace-operation-progress.test.ts | 58 ++++ src/lib/workspace-operation-progress.ts | 24 ++ src/routes/+layout.svelte | 3 + src/routes/aggregate/+page.svelte | 23 +- src/routes/exports/+page.svelte | 31 ++- src/routes/gists/+page.svelte | 19 +- 17 files changed, 511 insertions(+), 58 deletions(-) create mode 100644 src/lib/components/WorkspaceOperationProgress.svelte create mode 100644 src/lib/workspace-operation-progress.test.ts create mode 100644 src/lib/workspace-operation-progress.ts diff --git a/docs/wiki/Changelog.md b/docs/wiki/Changelog.md index dd62c36..5e1e6fa 100644 --- a/docs/wiki/Changelog.md +++ b/docs/wiki/Changelog.md @@ -8,6 +8,17 @@ production deployment and real-provider acceptance require separate evidence. ## Unreleased +### 2026-11-01 - Foreground cloud operation loading + +- Keep saves, publication generation, and Gist refresh in a visible foreground + loading dialog. Freeze background editing and navigation until the operation + settles, while keeping explicit confirmation dialogs usable. +- Retain drafts and pending/repair feedback when cloud confirmation is missing; + only confirmed remote commits finalize saves and publication links. +- Capture the publication profile, target, and filename before asynchronous + generation so the result stays attached to the original operation. Initialize + export drafts before checking for unsaved changes on first load. + ### 2026-10-31 - Explicit device reset and fresh connection - Added a confirmed Settings recovery action for devices whose original Gist was diff --git a/docs/wiki/Changelog.zh-CN.md b/docs/wiki/Changelog.zh-CN.md index 1223980..04df749 100644 --- a/docs/wiki/Changelog.zh-CN.md +++ b/docs/wiki/Changelog.zh-CN.md @@ -7,6 +7,14 @@ ## 未发布 +### 2026-11-01 - 云端操作前台等待状态 + +- 保存、发布生成与 Gist 刷新统一显示前台 loading,等待期间禁止编辑背景内容或切换页面, + 需要用户选择的确认弹窗仍可正常操作。 +- 未获得云端确认时保留草稿与待处理/修复提示;只有远端提交确认后才完成保存并更新发布链接。 +- 发布前固定配置、目标与文件名,避免生成期间的状态变化导致发布内容与操作对象混用。 +- 客户端导出先初始化草稿再检查变更,避免首次加载时误判为未保存并锁住发布按钮。 + ### 2026-10-31 - 显式设备重置与重新连接 - 在设置中增加需确认的恢复入口,支持原 Gist 已删除或不可访问、退出登录和云端加载失败的场景。 diff --git a/e2e/gists-readonly.spec.ts b/e2e/gists-readonly.spec.ts index e78adbf..66313fc 100644 --- a/e2e/gists-readonly.spec.ts +++ b/e2e/gists-readonly.spec.ts @@ -12,7 +12,7 @@ for (const variant of [ test(`Gists stays read-only while viewing and refreshing all file kinds (${variant.name})`, async ({ page, context, - }) => { + }, testInfo) => { await page.setViewportSize(variant); const errors: string[] = []; const writes: string[] = []; @@ -71,7 +71,11 @@ for (const variant of [ await expect(page).toHaveURL(/\/gists$/); await expect(page).toHaveTitle("Gists - SubMan"); await expect(page.locator(".app-header-link-connected")).toBeVisible(); - const main = page.getByRole("main"); + const main = page.locator("main"); + await expect(main.locator(".gh-box.shadow-sm")).toHaveAttribute( + "aria-busy", + "false", + ); await expect(main.getByRole("heading", { name: "Gists" })).toBeVisible(); await expect( main.getByText(variant.locale === "en" ? "Read-only" : "只读", { @@ -116,15 +120,50 @@ for (const variant of [ "data-copied-url", rawUrl, ); - await Promise.all([ - page.waitForResponse(gistUrl), - main - .getByRole("button", { - name: variant.locale === "en" ? "Refresh" : "刷新", - exact: true, - }) - .click(), - ]); + let release = () => {}; + const held = new Promise((resolve) => { + release = resolve; + }); + let requests = 0; + await context.route(gistUrl, async (route) => { + requests += 1; + await held; + await route.fallback(); + }); + await main + .getByRole("button", { + name: variant.locale === "en" ? "Refresh" : "刷新", + exact: true, + }) + .click(); + const waiting = page.getByRole("dialog", { + name: + variant.locale === "en" + ? "Loading workspace files..." + : "正在加载工作区文件...", + exact: true, + }); + await expect(waiting).toBeVisible(); + await expect(waiting).toHaveAttribute("aria-busy", "true"); + await expect(main.locator(".gh-box.shadow-sm")).toHaveAttribute( + "aria-busy", + "true", + ); + await page.keyboard.press("Escape"); + await expect(waiting).toBeVisible(); + await expect(waiting).toHaveCSS("opacity", "1"); + await page.screenshot({ + path: testInfo.outputPath("gists-refresh-loading.png"), + }); + release(); + await expect(waiting).toHaveCount(0); + await expect( + main.getByRole("button", { + name: variant.locale === "en" ? "Refresh" : "刷新", + exact: true, + }), + ).toBeEnabled(); + expect(requests).toBe(1); await expect(main.locator(".gh-box-row")).toHaveCount(5); await expect(main.getByRole("button")).toHaveCount(6); expect( diff --git a/e2e/ui-interactions.spec.ts b/e2e/ui-interactions.spec.ts index b0f672d..d141003 100644 --- a/e2e/ui-interactions.spec.ts +++ b/e2e/ui-interactions.spec.ts @@ -98,9 +98,9 @@ test("edit stays open and busy until the original cloud mutation is confirmed", "true", ); await expect(dialog.locator(".gh-action-button")).toBeDisabled(); - await expect( - dialog.getByRole("textbox", { name: "Name", exact: true }), - ).toHaveValue("Cloud-confirmed edit"); + await expect(dialog.getByLabel("Name", { exact: true })).toHaveValue( + "Cloud-confirmed edit", + ); await expect( page.getByRole("status").filter({ hasText: "Node updated" }), ).toHaveCount(0); @@ -278,6 +278,7 @@ test("automatic theme follows the OS while explicit light mode stays fixed", asy "rgb(13, 17, 23)", ); await page.reload(); + await expect(page.locator(".app-header-link-connected")).toBeVisible(); await expect(page.locator("body")).toHaveCSS( "background-color", "rgb(13, 17, 23)", diff --git a/e2e/workspace-reset.spec.ts b/e2e/workspace-reset.spec.ts index 3a5228e..386cd6c 100644 --- a/e2e/workspace-reset.spec.ts +++ b/e2e/workspace-reset.spec.ts @@ -455,6 +455,15 @@ test("reset remains reachable when browser persistence initialization fails", as }); }); await page.goto("/auth"); + await expect( + page + .getByRole("alert") + .filter({ + hasText: + "Cloud data could not be loaded. Check your connection and retry.", + }) + .first(), + ).toBeVisible(); const action = page.getByTestId("device-reset-action"); await expect(action).toBeEnabled(); await action.click(); diff --git a/e2e/workspace-v2.spec.ts b/e2e/workspace-v2.spec.ts index 5acb71e..c4ed58c 100644 --- a/e2e/workspace-v2.spec.ts +++ b/e2e/workspace-v2.spec.ts @@ -1329,7 +1329,7 @@ test("keeps an edit modal and draft open when the transaction aborts", async ({ ).toBeVisible(); await failNextPersistencePut(page, "AbortError"); await page.getByRole("button", { name: "Edit node" }).click(); - const dialog = page.getByRole("dialog"); + const dialog = page.getByRole("dialog", { name: "Edit Node", exact: true }); await dialog.getByLabel("Name").fill("Unsaved Edit"); await dialog.getByRole("button", { name: "Save", exact: true }).click(); @@ -1340,6 +1340,18 @@ test("keeps an edit modal and draft open when the transaction aborts", async ({ ).toBeVisible(); await expect(page.getByText("Node updated", { exact: true })).toHaveCount(0); await expect(page.getByText(/Workspace change was not saved/)).toHaveCount(1); + await expect( + page.getByRole("dialog", { + name: "Waiting for cloud confirmation...", + exact: true, + }), + ).toHaveCount(0); + await page + .getByLabel("Name", { exact: true }) + .fill("Retained Draft After Failure"); + await expect(page.getByLabel("Name", { exact: true })).toHaveValue( + "Retained Draft After Failure", + ); const stored = await readIndexedDb(page); expect(((stored.snapshot as JsonRecord).nodes as JsonRecord[])[0]?.name).toBe( existing.name, @@ -1552,7 +1564,7 @@ test("cloud load failures keep cached data hidden and prevent offline local edit test("resource save keeps its draft and withholds success until cloud commitment", async ({ page, context, -}) => { +}, testInfo) => { await seedIndexedDb(page, persistenceRecord()); await seedAuth(page, { session: "fixture-confirmed-save-token" }); let release = () => {}; @@ -1569,6 +1581,25 @@ test("resource save keeps its draft and withholds success until cloud commitment await page.goto("/nodes"); await addNode(page, "Cloud Confirmed Node", "vless://confirmed.example"); await expect.poll(() => mutations.length).toBe(1); + const waiting = page.getByRole("dialog", { + name: "Waiting for cloud confirmation...", + exact: true, + }); + await expect(waiting).toBeVisible(); + await expect(waiting).toHaveAttribute("aria-busy", "true"); + expect( + await page + .getByLabel("Name", { exact: true }) + .evaluate((element) => Boolean(element.closest("[inert]"))), + ).toBe(true); + await page.keyboard.press("Escape"); + await expect(waiting).toBeVisible(); + await page.mouse.click(4, 4); + await expect(waiting).toBeVisible(); + await page.evaluate(() => { + document.querySelector('a[href="/gists"]')?.click(); + }); + await expect(page).toHaveURL(/\/nodes$/); await expect(page.getByText("Resource added", { exact: true })).toHaveCount( 0, ); @@ -1578,11 +1609,21 @@ test("resource save keeps its draft and withholds success until cloud commitment await expect(page.getByLabel("Raw URI", { exact: true })).toHaveValue( "vless://confirmed.example", ); + await expect(waiting).toHaveCSS("opacity", "1"); + await page.screenshot({ + path: testInfo.outputPath("resource-cloud-confirmation.png"), + }); release(); + await expect(waiting).toHaveCount(0); await expect(page.getByText("Resource added", { exact: true })).toBeVisible(); await expect( page.getByText("Cloud Confirmed Node", { exact: true }), ).toBeVisible(); + await expect(page.getByLabel("Raw URI", { exact: true })).toHaveCount(0); + await expect( + page.getByRole("button", { name: "New Resource", exact: true }), + ).toBeEnabled(); + expect(mutations).toHaveLength(1); const stored = await readIndexedDb(page); expect((stored.binding as JsonRecord).revision).toBe(1); expect( @@ -1888,6 +1929,111 @@ test("allows one tab to take over an expired lease without duplicate submission" expect(requestCount).toBe(1); }); +test("target rename hands keyboard focus from cloud waiting through Save and Publish confirmations", async ({ + context, + page, +}) => { + const data = aggregateData(); + await seedIndexedDb( + page, + persistenceRecord({ + snapshot: snapshot({ data, gists: [gistMetadata()] }), + binding: binding({ baseline: workspaceDocument({ data }) }), + }), + ); + await seedAuth(page, { session: "fixture-target-rename-token" }); + let releaseRule = () => {}; + const heldRule = new Promise((resolve) => { + releaseRule = resolve; + }); + let releaseTarget = () => {}; + const heldTarget = new Promise((resolve) => { + releaseTarget = resolve; + }); + const mutations: JsonRecord[] = []; + let remoteData = structuredClone(data); + await context.route("**/api/workspaces/**/mutations", async (route) => { + const mutation = route.request().postDataJSON() as JsonRecord; + mutations.push(mutation); + if (mutation.kind === "aggregate.upsert") await heldRule; + if (mutation.kind === "publish-target.upsert") await heldTarget; + const result = committedResult(mutation, remoteData); + remoteData = (result.document as JsonRecord).data as JsonRecord; + await route.fulfill({ json: result }); + }); + await page.goto("/aggregate"); + await page + .locator('.gh-rule-header-actions button[aria-haspopup="menu"]') + .click(); + await page + .getByRole("button", { name: "E2E Aggregate", exact: true }) + .click(); + await page.getByLabel("Rule Name", { exact: true }).fill("Renamed Aggregate"); + await page.getByLabel("Select Target", { exact: true }).click(); + await page.getByRole("button", { name: "E2E Target", exact: true }).click(); + await page.getByLabel("Output File", { exact: true }).fill("renamed.txt"); + const save = page.getByRole("button", { + name: "Save and Publish", + exact: true, + }); + await save.focus(); + await page.keyboard.press("Enter"); + const waiting = page.getByRole("dialog", { + name: "Waiting for cloud confirmation...", + exact: true, + }); + await expect.poll(() => mutations.length).toBe(1); + await expect(waiting).toBeVisible(); + await expect(waiting).toBeFocused(); + expect(mutations[0]?.kind).toBe("aggregate.upsert"); + releaseRule(); + const rename = page.getByRole("dialog", { + name: "Change output file", + exact: true, + }); + await expect(rename).toBeVisible(); + await expect( + rename.getByRole("button", { name: "Continue", exact: true }), + ).toBeFocused(); + await page.keyboard.press("Enter"); + const cleanup = page.getByRole("dialog", { + name: "Previous output file", + exact: true, + }); + await expect(cleanup).toBeVisible(); + const keep = cleanup.getByRole("button", { + name: "Keep old file", + exact: true, + }); + await keep.focus(); + await expect(keep).toBeFocused(); + expect( + await keep.evaluate((element) => Boolean(element.closest("[inert]"))), + ).toBe(false); + await page.keyboard.press("Enter"); + await expect.poll(() => mutations.length).toBe(2); + await expect(waiting).toBeVisible(); + await expect(waiting).toBeFocused(); + expect(mutations[1]?.kind).toBe("publish-target.upsert"); + expect((mutations[1]?.payload as JsonRecord).previousFileCleanup).toBe( + "keep", + ); + releaseTarget(); + await expect(waiting).toHaveCount(0); + await expect( + page.getByText("Published successfully to GitHub Gist", { exact: true }), + ).toBeVisible(); + await expect(page.getByLabel("Output File", { exact: true })).toHaveValue( + "renamed.txt", + ); + await expect(save).toBeEnabled(); + expect(mutations.map((mutation) => mutation.kind)).toEqual([ + "aggregate.upsert", + "publish-target.upsert", + "aggregate.publish", + ]); +}); + test("Save and Publish stops when the target draft cannot be persisted", async ({ context, page, @@ -2175,6 +2321,97 @@ test("aggregate publish keeps one mutation across retry, reload, and recovery", ).toBeVisible(); }); +test("client export publication locks the editor until cloud confirmation", async ({ + context, + page, +}, testInfo) => { + const data = clientExportData(); + const profiles = data.clientExports as JsonRecord[]; + profiles.push({ + ...structuredClone(profiles[0]), + id: "other-export-e2e", + name: "Other Client Export", + fileName: "other-client.json", + lastPublishedAt: null, + lastPublishedUrl: null, + }); + await seedIndexedDb( + page, + persistenceRecord({ + snapshot: snapshot({ data, gists: [gistMetadata()] }), + binding: binding({ baseline: workspaceDocument({ data }) }), + }), + ); + await seedAuth(page, { session: "fixture-export-confirmation-token" }); + let release = () => {}; + const held = new Promise((resolve) => { + release = resolve; + }); + const mutations: JsonRecord[] = []; + await context.route("**/api/workspaces/**/mutations", async (route) => { + const mutation = route.request().postDataJSON() as JsonRecord; + mutations.push(mutation); + await held; + await fulfillCommitted(route, mutation, data); + }); + await page.goto("/exports"); + await expect(page.locator(".app-header-link-connected")).toBeVisible(); + await expect( + page.getByText("Generate a current preview before publishing.", { + exact: true, + }), + ).toBeVisible(); + await page.getByRole("button", { name: "Generate Preview" }).click(); + await page.getByRole("button", { name: "Publish", exact: true }).click(); + await expect.poll(() => mutations.length).toBe(1); + const waiting = page.getByRole("dialog", { + name: "Waiting for cloud confirmation...", + exact: true, + }); + await expect(waiting).toBeVisible(); + expect( + await page + .getByLabel("Listen Port", { exact: true }) + .evaluate((element) => Boolean(element.closest("[inert]"))), + ).toBe(true); + expect( + await page + .locator("button.gh-row-main") + .filter({ hasText: "Other Client Export" }) + .evaluate((element) => Boolean(element.closest("[inert]"))), + ).toBe(true); + await page.keyboard.press("Escape"); + await expect(waiting).toBeVisible(); + await expect(page.getByText("Published sing-box config")).toHaveCount(0); + const liveUrl = `https://gist.githubusercontent.com/e2e/${GIST_ID}/raw/client-e2e.json`; + await expect(page.getByText(liveUrl, { exact: true })).toHaveCount(0); + await expect( + page.getByText(EXISTING_EXPORT_URL, { exact: true }), + ).toBeVisible(); + expect(mutations[0]?.kind).toBe("client-export.publish"); + expect((mutations[0]?.payload as JsonRecord).profileId).toBe("export-e2e"); + expect( + ((mutations[0]?.payload as JsonRecord).output as JsonRecord).fileName, + ).toBe("client-e2e.json"); + await expect(waiting).toHaveCSS("opacity", "1"); + await page.screenshot({ + path: testInfo.outputPath("export-cloud-confirmation.png"), + }); + release(); + await expect(waiting).toHaveCount(0); + await expect(page.getByText("Published sing-box config")).toBeVisible(); + await expect(page.getByText(liveUrl, { exact: true })).toBeVisible(); + await page.getByLabel("Listen Port", { exact: true }).fill("2090"); + await expect(page.getByLabel("Listen Port", { exact: true })).toHaveValue( + "2090", + ); + await page.getByRole("button", { name: /Other Client Export/ }).click(); + await expect(page.getByLabel("File Name", { exact: true })).toHaveValue( + "other-client.json", + ); + expect(mutations).toHaveLength(1); +}); + test("client export publication hides its live link until remote commitment", async ({ context, page, @@ -2209,6 +2446,7 @@ test("client export publication hides its live link until remote commitment", as }); await page.goto("/exports"); + await expect(page.locator(".app-header-link-connected")).toBeVisible(); await expect( page.getByText(EXISTING_EXPORT_URL, { exact: true }), ).toBeVisible(); @@ -2227,6 +2465,22 @@ test("client export publication hides its live link until remote commitment", as .getByRole("status") .getByText("Cloud save pending; retrying", { exact: true }), ).toBeVisible(); + await expect( + page.getByRole("dialog", { + name: "Waiting for cloud confirmation...", + exact: true, + }), + ).toHaveCount(0); + const syncStatusLink = page.getByRole("link", { + name: "View sync status", + exact: true, + }); + await expect(syncStatusLink).toBeVisible(); + expect( + await syncStatusLink.evaluate((element) => + Boolean(element.closest("[inert]")), + ), + ).toBe(false); await expect(page.getByText("Published sing-box config")).toHaveCount(0); await expect( page.getByText(EXISTING_EXPORT_URL, { exact: true }), diff --git a/src/lib/components/ActionButton.svelte b/src/lib/components/ActionButton.svelte index c9b1ab7..03a218a 100644 --- a/src/lib/components/ActionButton.svelte +++ b/src/lib/components/ActionButton.svelte @@ -9,6 +9,7 @@ import type { WorkspaceFeedbackState, WorkspaceOperationPresentation, } from "$lib/workspace-operation-presenter"; +import { withWorkspaceOperation } from "$lib/workspace-operation-progress"; import { workspaceSyncStatus } from "$lib/workspace-sync-status"; let { @@ -62,7 +63,8 @@ async function run() { busy = true; feedbackStatus = "idle"; try { - await action(); + if (workspace) await withWorkspaceOperation(action); + else await action(); if (!mounted) return; if (feedback && feedback !== previous) feedbackStatus = feedback.feedbackState; diff --git a/src/lib/components/Dialog.svelte b/src/lib/components/Dialog.svelte index d6bd9fe..0e490fb 100644 --- a/src/lib/components/Dialog.svelte +++ b/src/lib/components/Dialog.svelte @@ -12,6 +12,8 @@ let { initialFocus, className = "max-w-2xl", mobileSheet = true, + dismissible = true, + busy = false, children, }: { label?: string; @@ -21,13 +23,23 @@ let { initialFocus?: string; className?: string; mobileSheet?: boolean; + dismissible?: boolean; + busy?: boolean; children: Snippet; } = $props(); + +function close() { + if (dismissible) onclose(); +} -
- - + + {#if $confirmDialog.open} resolveConfirm(false)} initialFocus="[data-confirm]" className="max-w-md" mobileSheet={false}>
diff --git a/src/routes/aggregate/+page.svelte b/src/routes/aggregate/+page.svelte index c8303eb..80e78c3 100644 --- a/src/routes/aggregate/+page.svelte +++ b/src/routes/aggregate/+page.svelte @@ -708,21 +708,19 @@ async function deleteRule(): Promise { async function publishSaved(): Promise { const token = $authState.token; const gistId = $appState.activeGistId; - if (!token || !gistId || !selectedTargetId) return; + const targetId = selectedTargetId; + const state = $appState; + if (!token || !gistId || !targetId || publishing) return; publishing = true; try { - const target = $appState.publishTargets.find( - (item) => item.id === selectedTargetId, - ); - const rule = $appState.aggregates.find( - (item) => item.id === target?.ruleId, - ); + const target = state.publishTargets.find((item) => item.id === targetId); + const rule = state.aggregates.find((item) => item.id === target?.ruleId); if (!target || !rule) throw new Error("Publish target not found"); const output = await buildAggregateOutput( rule, - $appState.nodes, - $appState.subscriptions, + state.nodes, + state.subscriptions, ); if (output.errors.length > 0) { throw new Error(output.errors[0] ?? "Publish failed"); @@ -742,9 +740,8 @@ async function publishSaved(): Promise { if (!presentation.remoteCommitted || result.status !== "remote-committed") return; publishUrl = - result.state.publishTargets.find( - (target) => target.id === selectedTargetId, - )?.lastPublishedUrl ?? null; + result.state.publishTargets.find((target) => target.id === targetId) + ?.lastPublishedUrl ?? null; if (output.subscriptionIssues.length > 0) { showToast( $t( @@ -775,7 +772,7 @@ async function publish(): Promise { } async function saveAndPublish(): Promise { - if (!isWorkspaceConnected) return; + if (!isWorkspaceConnected || publishing) return; publishing = true; try { if (ruleDirty) { diff --git a/src/routes/exports/+page.svelte b/src/routes/exports/+page.svelte index 65b2bea..56cb720 100644 --- a/src/routes/exports/+page.svelte +++ b/src/routes/exports/+page.svelte @@ -86,6 +86,12 @@ $: selectedProfile = $: selectedRule = $appState.aggregates.find((rule) => rule.id === selectedProfile?.ruleId) ?? null; +$: if ( + selectedProfile && + syncedDraftProfileSignature !== getProfileDraftSignature(selectedProfile) +) { + syncDraftFromProfile(selectedProfile); +} $: profileCount = $appState.clientExports.length; $: canCreateProfile = !!firstRule; $: ruleOptions = $appState.aggregates.map((rule) => ({ @@ -158,13 +164,6 @@ $: publishedUrl = selectedProfileId ? getCommittedClientExportUrl(selectedProfileId, $appState) : null; -$: if ( - selectedProfile && - syncedDraftProfileSignature !== getProfileDraftSignature(selectedProfile) -) { - syncDraftFromProfile(selectedProfile); -} - function getProfileDraftSignature(profile: ClientExportProfile): string { return JSON.stringify({ id: profile.id, @@ -419,16 +418,20 @@ async function downloadPreview(): Promise { async function publishPreview(): Promise { const token = $authState.token; const gistId = $appState.activeGistId; - if (!token || !gistId || !selectedProfile) return; + const profile = selectedProfile; + const rule = selectedRule; + const state = $appState; + if (!token || !gistId || !profile || publishing) return; + const profileId = profile.id; + const fileName = normalizeExportFileName(profile.fileName); publishing = true; try { - const profileId = selectedProfile.id; const publicationBuild = await buildSingBoxClientConfig( - selectedProfile, - selectedRule, - $appState.nodes, - $appState.subscriptions, + profile, + rule, + state.nodes, + state.subscriptions, ); if ( publicationBuild.errors.length > 0 || @@ -443,7 +446,7 @@ async function publishPreview(): Promise { payload: { profileId, output: { - fileName: normalizeExportFileName(selectedProfile.fileName), + fileName, content: publicationBuild.content, }, }, diff --git a/src/routes/gists/+page.svelte b/src/routes/gists/+page.svelte index 6ef17e8..c9b5560 100644 --- a/src/routes/gists/+page.svelte +++ b/src/routes/gists/+page.svelte @@ -26,6 +26,7 @@ import { type WorkspaceFileKind, } from "$lib/workspace-file-inventory"; import { requireWorkspaceIdentity } from "$lib/workspace-identity"; +import { withWorkspaceOperation } from "$lib/workspace-operation-progress"; import { getBrowserWorkspaceBinding, initializeBrowserWorkspacePersistence, @@ -80,16 +81,18 @@ function workspaceFailureMessage(error: unknown, fallback: string): string { async function refreshWorkspace() { const token = $authState.token; - if (!token) return; + if (!token || loading) return; loading = true; try { - await initializeBrowserWorkspacePersistence(); - const identity = requireWorkspaceIdentity( - $appState, - getBrowserWorkspaceBinding(), - ); - workspace = await getGist(token, identity.gistId); + await withWorkspaceOperation(async () => { + await initializeBrowserWorkspacePersistence(); + const identity = requireWorkspaceIdentity( + $appState, + getBrowserWorkspaceBinding(), + ); + workspace = await getGist(token, identity.gistId); + }, "Loading workspace files..."); } catch (error) { setStatus(workspaceFailureMessage(error, "Failed to fetch"), "error"); } finally { @@ -131,7 +134,7 @@ onMount(() => { {/if}
{/if} -
+
From 6daed4ab999a572ae663b3ebdbcb435dcd9d818e Mon Sep 17 00:00:00 2001 From: KnowSky404 Date: Sun, 1 Nov 2026 15:27:30 +0800 Subject: [PATCH 2/2] test(ui): wait for foreground loading before interactions --- docs/wiki/Changelog.md | 2 ++ docs/wiki/Changelog.zh-CN.md | 1 + e2e/ui-polish.spec.ts | 39 +++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/docs/wiki/Changelog.md b/docs/wiki/Changelog.md index 5e1e6fa..5e5ef35 100644 --- a/docs/wiki/Changelog.md +++ b/docs/wiki/Changelog.md @@ -18,6 +18,8 @@ production deployment and real-provider acceptance require separate evidence. - Capture the publication profile, target, and filename before asynchronous generation so the result stays attached to the original operation. Initialize export drafts before checking for unsaved changes on first load. +- Wait for Gist refresh completion before exercising file actions in browser + tests, and keep navigation tests stable while the scroll button label changes. ### 2026-10-31 - Explicit device reset and fresh connection diff --git a/docs/wiki/Changelog.zh-CN.md b/docs/wiki/Changelog.zh-CN.md index 04df749..5650472 100644 --- a/docs/wiki/Changelog.zh-CN.md +++ b/docs/wiki/Changelog.zh-CN.md @@ -14,6 +14,7 @@ - 未获得云端确认时保留草稿与待处理/修复提示;只有远端提交确认后才完成保存并更新发布链接。 - 发布前固定配置、目标与文件名,避免生成期间的状态变化导致发布内容与操作对象混用。 - 客户端导出先初始化草稿再检查变更,避免首次加载时误判为未保存并锁住发布按钮。 +- 浏览器测试等待 Gist 刷新完成后再操作文件按钮,并在导航翻页按钮文案变化时保持定位稳定。 ### 2026-10-31 - 显式设备重置与重新连接 diff --git a/e2e/ui-polish.spec.ts b/e2e/ui-polish.spec.ts index b735a5b..cb64ba7 100644 --- a/e2e/ui-polish.spec.ts +++ b/e2e/ui-polish.spec.ts @@ -102,23 +102,28 @@ test("mobile navigation reveals settings and keeps the selected page visible", a await seedUiWorkspace(page, context); await page.goto("/"); await expect(page.locator(".app-header-link-connected")).toBeVisible(); + const navigation = page.getByRole("navigation", { name: "Primary" }); + const scroll = page.locator(".app-nav-scroll"); for (let attempt = 0; attempt < 4; attempt++) { - const more = page.getByRole("button", { - name: "More navigation items", - exact: true, - }); - if (!(await more.count())) break; - const previous = await page - .locator("nav") - .evaluate((node) => node.scrollLeft); - await more.click(); + const previous = await navigation.evaluate((node) => ({ + left: node.scrollLeft, + remaining: node.scrollWidth - node.clientWidth - node.scrollLeft, + })); + if (previous.remaining <= 1) break; + await expect(scroll).toHaveAttribute("aria-label", "More navigation items"); + await scroll.click(); await expect - .poll(() => page.locator("nav").evaluate((node) => node.scrollLeft)) - .toBeGreaterThan(previous); + .poll(() => navigation.evaluate((node) => node.scrollLeft)) + .toBeGreaterThan(previous.left); + const atEnd = await navigation.evaluate( + (node) => node.scrollWidth - node.clientWidth - node.scrollLeft <= 1, + ); + await expect(scroll).toHaveAttribute( + "aria-label", + atEnd ? "Previous navigation items" : "More navigation items", + ); } - const settings = page - .getByRole("navigation", { name: "Primary" }) - .getByRole("link", { name: "Settings" }); + const settings = navigation.getByRole("link", { name: "Settings" }); await expect(settings).toBeInViewport({ ratio: 1 }); await settings.click(); await expect(page).toHaveURL(/\/auth$/); @@ -219,6 +224,11 @@ test("Gist filenames expose real raw links and accessible icon labels", async ({ await seedUiWorkspace(page, context); await page.goto("/gists"); await expect(page.locator(".app-header-link-connected")).toBeVisible(); + await expect(page.locator(".gh-box.shadow-sm")).toHaveAttribute( + "aria-busy", + "false", + ); + await expect(page.getByRole("dialog")).toHaveCount(0); await expect( page.getByRole("link", { name: "subman.json · Open Raw" }), ).toHaveAttribute( @@ -227,6 +237,7 @@ test("Gist filenames expose real raw links and accessible icon labels", async ({ ); const copy = page.getByRole("button", { name: "Copy Raw URL", exact: true }); await copy.focus(); + await expect(copy).toBeFocused(); await expect(page.getByRole("tooltip")).toHaveText("Copy Raw URL"); });