From 0574a85632350f38329c02abee44cba3219f276f Mon Sep 17 00:00:00 2001 From: que01 Date: Mon, 12 Oct 2026 15:31:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A2=84=E8=A7=88=20l?= =?UTF-8?q?oading=20=E4=B8=8E=E5=AA=92=E4=BD=93=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/taro/config/index.ts | 15 ++++++++++++++- apps/taro/src/runtime/workspace.tsx | 2 +- apps/taro/test/browser/preview.spec.ts | 19 ++++++++++++++++++- docs/template-completion-rules.md | 4 ++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/apps/taro/config/index.ts b/apps/taro/config/index.ts index 65f474e..417af4f 100644 --- a/apps/taro/config/index.ts +++ b/apps/taro/config/index.ts @@ -82,6 +82,19 @@ export default defineConfig({ h5: { publicPath: process.env.PREVIEW_PUBLIC_PATH || "/", router: { mode: "hash" }, - devServer: { host: "0.0.0.0", port: Number(process.env.PREVIEW_PORT || 3002) }, + devServer: { + host: "0.0.0.0", + port: Number(process.env.PREVIEW_PORT || 3002), + proxy: { + "/media": { + target: + process.env.MEDIA_API_TARGET || + (process.env.API_BASE_URL?.startsWith("http") + ? new URL(process.env.API_BASE_URL).origin + : "http://localhost:3001"), + changeOrigin: true, + }, + }, + }, }, }); diff --git a/apps/taro/src/runtime/workspace.tsx b/apps/taro/src/runtime/workspace.tsx index 155816c..25c13b9 100644 --- a/apps/taro/src/runtime/workspace.tsx +++ b/apps/taro/src/runtime/workspace.tsx @@ -43,7 +43,7 @@ export function WorkspaceProvider({ children }: PropsWithChildren) { .catch((error: unknown) => setError(error instanceof Error ? error.message : "加载失败,请重试"), ) - .finally(() => setLoading(!editorPreview)); + .finally(() => setLoading(false)); }, []); useEffect(reload, [reload]); return ( diff --git a/apps/taro/test/browser/preview.spec.ts b/apps/taro/test/browser/preview.spec.ts index a2fed53..8793272 100644 --- a/apps/taro/test/browser/preview.spec.ts +++ b/apps/taro/test/browser/preview.spec.ts @@ -83,14 +83,31 @@ test("加载失败提供重试", async ({ page }) => { await page.goto("/"); await expect(page.getByText("测试服务暂不可用")).toBeVisible(); await expect(page.getByText("重试")).toBeVisible(); + await page.unroute("**/public/workspace**"); + const response = page.waitForResponse((response) => response.url().includes("/public/workspace")); + await page.getByText("重试", { exact: true }).click(); + expect((await response).ok()).toBe(true); + await expect(page.locator(".runtime-state")).toHaveCount(0); + await expect(page.locator("[data-editor-target]").first()).toBeVisible(); }); test("林境模板使用真实品牌数据与独立路由", async ({ page }) => { const errors: string[] = []; page.on("pageerror", (error) => errors.push(error.message)); - await page.goto("http://localhost:3003/"); + await page.goto("http://localhost:3003/#/pages/home/index"); await expect(page.locator(".founder-name")).toContainText("林"); await expect(page.locator(".stat-value")).toHaveCount(4); + await expect + .poll(() => + page + .locator(".editorial-home img") + .evaluateAll( + (images) => + images.length > 0 && + images.every((image) => (image as HTMLImageElement).naturalWidth > 0), + ), + ) + .toBe(true); await page.getByText("主理人与我", { exact: true }).click(); await expect(page.locator(".editorial-profile .founder")).toBeVisible(); await expect(page.locator(".trust-card").first()).toBeVisible(); diff --git a/docs/template-completion-rules.md b/docs/template-completion-rules.md index 2ee5075..50b8592 100644 --- a/docs/template-completion-rules.md +++ b/docs/template-completion-rules.md @@ -52,6 +52,10 @@ CI 可执行 pnpm test:template-doctor 和诊断命令。新模板自动扫描 ## 保存与预览补充 +独立 H5 预览须覆盖真实公开数据加载、失败提示及重试恢复;请求成功或失败后都必须退出 loading,不能仅以 tabbar 出现判定页面可用。编辑器预览继续等待 workspaceDraft,不得因公开请求结束而提前显示失败。 + +H5 开发预览的 `/media` 请求须代理至 API 媒体服务,默认 `http://localhost:3001`,可通过 `MEDIA_API_TARGET` 覆盖,或从绝对地址 `API_BASE_URL` 推导 origin。图片回归检查实际加载尺寸,不能只检查图片节点存在;生产环境仍由部署网关提供 `/media` 路由。 + 保存请求仅包含允许修改的字段及新配置。禁止在新 config 后展开带旧 config 的完整品牌对象,禁止内容编辑携带 visualTemplateKey 触发模板切换权限。共享表单保存须保留跨区域修改。 Admin 预览读取当前品牌的草稿 Runtime,公开接口读取已发布快照。两者共用投影逻辑;保存后预览、重新加载预览、发布后公开读取必须分别测试。不得用 mock 返回最新数据掩盖真实预览接口仍读旧发布快照。