From bb94d80e133dc18d2438f45e0436837720053a84 Mon Sep 17 00:00:00 2001 From: que01 Date: Tue, 13 Oct 2026 23:44:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20H5=20=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E9=AB=98=E5=BA=A6=E4=BB=A4=E7=89=8C=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 共享按钮令牌声明在 app.css 的 page 选择器里,而 H5 渲染树没有 page 元素,导致 var(--brand-button-height) 解析失败、min-height 退化成 auto:H5 预览按钮实际高 38px (内容撑开),与小程序 88rpx(375px 视口等于 44px)不一致,也违反模板完成度规则的 双端 reset 一致要求。 - 令牌改为同时声明在 page 与 body 上,值仍只写一次;微信端取 page,H5 取 body; - 新增浏览器守卫,断言首页按钮 min-height 解析为 44px 且实际高度一致; - 在模板完成度规则中记录该根因,避免声明被挪回单一 page 选择器。 验证:weapp 产物输出 page,body{--brand-button-height:88rpx},H5 输出 page,body{2.2rem}; 浏览器实测 375px 视口下 min-height/height 均为 44px,430px 视口为 50.45px,与小程序 rpx 缩放一致;把声明改回 page-only 后守卫按预期失败(Received: "auto"),恢复后 12 项 浏览器回归全部通过;六类产物指纹残留为 0;format、lint、typecheck 通过。 --- apps/taro/src/app.css | 4 ++++ apps/taro/test/browser/preview.spec.ts | 14 ++++++++++++++ docs/template-completion-rules.md | 2 ++ 3 files changed, 20 insertions(+) diff --git a/apps/taro/src/app.css b/apps/taro/src/app.css index 05126d3..51fd47f 100644 --- a/apps/taro/src/app.css +++ b/apps/taro/src/app.css @@ -1,5 +1,9 @@ page { background: #fafaf9; +} +/* H5 渲染树里没有 page 元素,令牌必须同时声明在真实根节点 body 上,双端按钮高度才一致。 */ +page, +body { --brand-button-height: 88px; --brand-button-compact-height: 46px; } diff --git a/apps/taro/test/browser/preview.spec.ts b/apps/taro/test/browser/preview.spec.ts index a513200..00f1bb3 100644 --- a/apps/taro/test/browser/preview.spec.ts +++ b/apps/taro/test/browser/preview.spec.ts @@ -3,6 +3,20 @@ import { test, expect } from "@playwright/test"; // 产物会遮蔽 Taro 运行时命名,选择器同时接受源码名称与遮蔽名称。 const BUTTON_CORE = ":is(taro-button-core, appkit-button-core)"; const TABBAR = ":is(.taro-tabbar__tabbar, .appkit-tabbar__tabbar)"; +test("共享按钮令牌在 H5 生效并与小程序高度一致", async ({ page }) => { + await page.setViewportSize({ width: 375, height: 812 }); + await page.goto("/"); + const measured = await page + .locator(`.food-home .actions ${BUTTON_CORE}`) + .first() + .evaluate((element) => ({ + minHeight: getComputedStyle(element).minHeight, + height: element.getBoundingClientRect().height, + })); + // 750 设计宽度下 88rpx 在 375px 视口等于 44px;H5 若取不到令牌会退化成 auto。 + expect(measured.minHeight).toBe("44px"); + expect(measured.height).toBe(44); +}); test("真实 API 驱动首页、出摊和主理人视觉槽位", async ({ page }) => { const errors: string[] = []; page.on("pageerror", (error) => errors.push(error.message)); diff --git a/docs/template-completion-rules.md b/docs/template-completion-rules.md index 90b5178..6d1b48f 100644 --- a/docs/template-completion-rules.md +++ b/docs/template-completion-rules.md @@ -74,6 +74,8 @@ Taro 小程序构建默认会把 CSS 中的 HTML 标签选择器重写为 `.h5-< 共享 reset 必须让微信 `