fix(h5): keep active Taro pages visible beside debug overlay
This commit is contained in:
parent
42f0f41bf1
commit
5eda60af17
@ -3,6 +3,7 @@ import { defineConfig, type UserConfigExport } from '@tarojs/cli'
|
|||||||
|
|
||||||
/** 本目录仅编 Taro H5;微信见上级 weapp 根,抖音见 tt/,小红书见 xhs/ */
|
/** 本目录仅编 Taro H5;微信见上级 weapp 根,抖音见 tt/,小红书见 xhs/ */
|
||||||
const target = 'h5'
|
const target = 'h5'
|
||||||
|
const devPort = Number(process.env.TARO_H5_PORT || 10086)
|
||||||
const defaultApi = process.env.TARO_APP_API || 'https://api.nomadro.cn'
|
const defaultApi = process.env.TARO_APP_API || 'https://api.nomadro.cn'
|
||||||
|
|
||||||
const h5ViteProxy = {
|
const h5ViteProxy = {
|
||||||
@ -96,7 +97,7 @@ export default defineConfig(async (merge) => {
|
|||||||
viteConfig.server = {
|
viteConfig.server = {
|
||||||
...(viteConfig.server || {}),
|
...(viteConfig.server || {}),
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: 10086,
|
port: devPort,
|
||||||
open: false,
|
open: false,
|
||||||
proxy: h5ViteProxy,
|
proxy: h5ViteProxy,
|
||||||
}
|
}
|
||||||
@ -109,7 +110,7 @@ export default defineConfig(async (merge) => {
|
|||||||
},
|
},
|
||||||
devServer: {
|
devServer: {
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: 10086,
|
port: devPort,
|
||||||
open: false,
|
open: false,
|
||||||
proxy: h5ViteProxy,
|
proxy: h5ViteProxy,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -8,7 +8,8 @@
|
|||||||
"build": "cross-env TARO_APP_TARGET=h5 node ./node_modules/@tarojs/cli/bin/taro build --type h5",
|
"build": "cross-env TARO_APP_TARGET=h5 node ./node_modules/@tarojs/cli/bin/taro build --type h5",
|
||||||
"dev:h5": "pnpm dev",
|
"dev:h5": "pnpm dev",
|
||||||
"build:h5": "pnpm build",
|
"build:h5": "pnpm build",
|
||||||
"smoke": "python ./scripts/_h5_smoke.py"
|
"smoke": "python ./scripts/_h5_smoke.py",
|
||||||
|
"test:home": "python ./scripts/test_home_visibility.py"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 3 versions",
|
"last 3 versions",
|
||||||
|
|||||||
49
apps/miniprogram/h5/scripts/test_home_visibility.py
Normal file
49
apps/miniprogram/h5/scripts/test_home_visibility.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
"""Browser regression: global app overlays must not hide Taro router pages.
|
||||||
|
|
||||||
|
Start H5 first. Set TARO_H5_TEST_URL to check a non-default port.
|
||||||
|
API requests are mocked so the check never depends on a production backend.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
|
||||||
|
from playwright.sync_api import sync_playwright, expect
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
origin = os.environ.get('TARO_H5_TEST_URL', 'http://127.0.0.1:10086').rstrip('/')
|
||||||
|
with sync_playwright() as playwright:
|
||||||
|
browser = playwright.chromium.launch()
|
||||||
|
try:
|
||||||
|
for width, height in [(390, 844), (1440, 900)]:
|
||||||
|
context = browser.new_context(viewport={'width': width, 'height': height})
|
||||||
|
page = context.new_page()
|
||||||
|
errors = []
|
||||||
|
page.on('pageerror', lambda error: errors.append(str(error)))
|
||||||
|
|
||||||
|
def mock_api(route):
|
||||||
|
# Exercise packaged offline defaults, including disconnected live config.
|
||||||
|
route.fulfill(status=503, content_type='application/json', body='{}')
|
||||||
|
|
||||||
|
context.route('**/api/**', mock_api)
|
||||||
|
context.route('**/ebook-api/**', mock_api)
|
||||||
|
context.route('**/community-api/**', mock_api)
|
||||||
|
page.goto(f'{origin}/#/pages/home/index', wait_until='domcontentloaded')
|
||||||
|
home = page.locator('.taro_page_show .hub-root')
|
||||||
|
expect(home).to_be_visible(timeout=30000)
|
||||||
|
expect(home).to_contain_text('nomadro')
|
||||||
|
expect(home).to_contain_text('随处工作')
|
||||||
|
expect(page.get_by_text('调试', exact=True).first).to_be_visible()
|
||||||
|
|
||||||
|
# Navigate and return without reloading to exercise stacked route pages.
|
||||||
|
page.evaluate("location.hash = '#/pages/nav/index'")
|
||||||
|
expect(page.locator('.taro_page_show .navmini-root, .taro_page_show .app-shell').first).to_be_visible(timeout=30000)
|
||||||
|
page.go_back(wait_until='domcontentloaded')
|
||||||
|
expect(home).to_be_visible(timeout=30000)
|
||||||
|
assert not errors, errors
|
||||||
|
print(f'PASS {width}x{height}: home, navigation, back, debug overlay; no runtime errors')
|
||||||
|
context.close()
|
||||||
|
finally:
|
||||||
|
browser.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@ -139,8 +139,9 @@ function App({ children }: PropsWithChildren) {
|
|||||||
// DebugFab 内部按 envVersion/NODE_ENV 自判;正式版 release 不渲染
|
// DebugFab 内部按 envVersion/NODE_ENV 自判;正式版 release 不渲染
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<RuntimeGuard>{children}</RuntimeGuard>
|
{/* Taro H5 hides stationed pages that are not the router's last child. */}
|
||||||
<DebugFab />
|
<DebugFab />
|
||||||
|
<RuntimeGuard>{children}</RuntimeGuard>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
4
apps/miniprogram/h5/src/assets.d.ts
vendored
Normal file
4
apps/miniprogram/h5/src/assets.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
declare module '*.png' {
|
||||||
|
const url: string
|
||||||
|
export default url
|
||||||
|
}
|
||||||
4
apps/miniprogram/tt/src/assets.d.ts
vendored
Normal file
4
apps/miniprogram/tt/src/assets.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
declare module '*.png' {
|
||||||
|
const url: string
|
||||||
|
export default url
|
||||||
|
}
|
||||||
58
docs/code-audit-2026-11-29.md
Normal file
58
docs/code-audit-2026-11-29.md
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# 2026-11-29 本地代码审计与修复
|
||||||
|
|
||||||
|
本轮保留工作区已有修改,未提交、推送或部署。页面布局、样式和文案未重新设计;冻结的 H5 游戏源码未改。使用 `.cursor/skills/nomadro-platform/SKILL.md` 核对公共服务面。
|
||||||
|
|
||||||
|
## 已修复
|
||||||
|
|
||||||
|
| 范围 | 问题与修改 |
|
||||||
|
|---|---|
|
||||||
|
| 门户导航 | 空分类提前返回导致后续 Hook 被条件调用;把空态返回移至所有 Hook 后,允许远程分类由空变为非空。 |
|
||||||
|
| 支付共享包 | 明确的 `audience: cn` 被冲突的 `isChinaUser: false` 覆盖;显式受众现在优先于检测提示,显式 region 仍保留最高优先级。 |
|
||||||
|
| SDK | 解构 `callTool` 丢失 `this`、工具路由重复维护、请求无超时、异常成功响应被当成空对象;改由工具清单派发,加 15 秒默认超时和响应校验。 |
|
||||||
|
| MCP | 加 15 秒超时及响应校验;HTTP 错误和无效 JSON 不再被误报为成功。 |
|
||||||
|
| 公共 CORS | 原先按字符串后缀判断,可能接受包含路径或非 HTTP 协议的伪 Origin;改为完整 URL origin 校验,始终声明 `Vary: Origin`。 |
|
||||||
|
| Hub 公共代理 | 上游 200 HTML/null 等无效响应不再被视为成功;申请备注仅接收字符串。 |
|
||||||
|
| 远程配置 | 合并并发强制刷新,启动后立即隐藏时跳过启动请求;完整配置参与变更检测,修复普通 copy/pages 修改不通知订阅者的问题。 |
|
||||||
|
| 小程序运行时 | 社交消息查询去掉对 `URLSearchParams` 全局的依赖;异常兜底补齐 `View`/`Text` 导入;`H5Box` 向原生 View 转发长按事件。 |
|
||||||
|
| 多端类型 | 修复编译器泛型、图片声明、Destination 地图字段、tabBar 字面量、组件样式属性、阅读返回字段等;微信类型检查改为检查实际使用的 H5 SoT,避免只检查残留目录。 |
|
||||||
|
| Coffeechat | 夏令时向前跳时,预约实际结束时间可能越过可用窗口;增加 UTC 结束边界检查与回归用例。 |
|
||||||
|
| PocketBase | 集合查询原先把 403/500/503 都当作不存在;仅 404 返回缺失,其他故障保留状态并抛出,避免错误进入建表流程。 |
|
||||||
|
|
||||||
|
## 依赖升级
|
||||||
|
|
||||||
|
- 门户和隔离的 `apps/hackrobot/vip` 分别更新 Next.js / eslint-config-next `16.1.6 → 16.4.6`、React / React DOM `19.2.3 → 19.2.9`,各自更新锁文件。
|
||||||
|
- 根项目 Node 最低版本修正为 `20.9.0`,符合 Next 16 要求。
|
||||||
|
- 工作区对兼容版本范围的间接依赖加安全修补:seroval `1.6.10`、@remix-run/router `1.23.3`、markdown-it 14 系列 `14.3.3`、linkify-it 5 系列 `5.0.2`。
|
||||||
|
- 移除 VIP 已不受支持的 `experimental.turbopackMemoryLimit`。保留构建命令的 Node 堆限制和 CPU 并发限制。
|
||||||
|
- 升级后旧 `.next/dev/types` 引用了已移除的 Next 内部类型;旧缓存保留为 `.next/dev/types-before-next-16-4-audit`,避免参与新检查。
|
||||||
|
|
||||||
|
## 验证结果
|
||||||
|
|
||||||
|
| 检查 | 结果 |
|
||||||
|
|---|---|
|
||||||
|
| `pnpm typecheck:all` | 门户、两个 Nomadro admin、H5、微信实际共享源码、抖音和独立 VIP 全部通过。 |
|
||||||
|
| `pnpm test:local` | 平台 5 项、微信运行时 9 项、社交 6 项、API 54 项(含 9 个 subtest)、Hub 边界 17 项全部通过;Hub 配置与分轨守卫通过。 |
|
||||||
|
| `pnpm build` | 升级后的门户生产构建通过。 |
|
||||||
|
| 两个 Nomadro admin build | 全部通过。 |
|
||||||
|
| 独立 VIP build | 升级后完整构建通过。 |
|
||||||
|
| H5 / 微信 / 抖音 build | 全部通过;抖音主包约 1.42 MB、book 分包 1.54 MB、总计 2.96 MB,通过现有体积校验。 |
|
||||||
|
| Python compileall | API services、hackrobot nomadmini backend、payjsapi 语法检查通过。 |
|
||||||
|
| 冻结锁文件离线安装 | `pnpm install --frozen-lockfile --offline` 通过。 |
|
||||||
|
|
||||||
|
测试通过不能证明所有业务或生产配置不存在问题。本轮未做生产写入、真实支付、微信/抖音真机验收或小红书平台提审验证。
|
||||||
|
|
||||||
|
## 尚未完成的项目问题
|
||||||
|
|
||||||
|
1. **依赖审计仍未清零。** 根工作区 `pnpm audit --prod` 从 184 条(low 22 / moderate 85 / high 71 / critical 6)降到 118 条(low 18 / moderate 58 / high 41 / critical 1)。这是依赖公告数,不是已证明可利用的业务漏洞数;不包含独立 VIP 的完整审计结果。剩余 critical 是 Taro components 的 Swiper 原型污染公告,要求 Swiper ≥12.1.2,不能直接跨多个主版本强制覆盖而假设兼容。Taro 4.0.9 与部分浮动的 4.3.0 插件也存在 peer 不匹配,需要统一版本后验证各端。
|
||||||
|
2. **全量 lint 未通过。** 更新后的 ESLint 扫描 2156 个文件,549 errors / 637 warnings;排除 Planka vendor 后仍有 307 errors / 100 warnings。主要是 React effect 同步更新、render 期间 refs/非纯操作、匿名组件和历史类型问题。新 eslint-config-next 对 React Compiler 规则的诊断有变化,因此与初始 478 errors / 627 warnings 不能直接比较。未关闭规则来掩盖告警。
|
||||||
|
3. **体积与弃用问题仍在。** H5 vendors 约 1.81 MB、common 约 1.39 MB(未压缩);微信有超过 webpack 推荐阈值的资产。Sass `@import`/legacy API、VIP middleware 命名仍有弃用提示。需要按模块拆包与迁移,不能只以构建通过判定已优化完成。
|
||||||
|
4. **仍需核对共享 PB 默认连接。** `packages/pb/src/index.ts` 的公共默认值仍是 `pocketbase.hackrobot.cn`;调用方未设置 env 时有跨产品数据连接风险。本轮未猜测新的 PB 公网地址;后续应按 Nomadro/VIP 的实际部署分别提供明确连接配置。
|
||||||
|
5. **覆盖范围有限。** Unity/Cocos 编辑器、小红书组装与平台运行、hackrobot admin-site/nomadmini 的端到端业务、所有生产数据库和真实外部服务均没有完整验收。当前工作不能标记为“所有项目问题已全部修复”。
|
||||||
|
|
||||||
|
新增日常入口:`pnpm typecheck:all` 和 `pnpm test:local`。详细终端日志保存在本地 `.tmp-audit-*.log`,依赖与 lint 原始 JSON 位于 `.tmp-audit-deps-final.json`、`.tmp-audit-eslint-final.json`。
|
||||||
|
|
||||||
|
## 后续:Taro H5 首页白屏修复
|
||||||
|
|
||||||
|
真实浏览器复现了首页 DOM 存在但不可见的问题。Taro router 使用 `:not(:last-child)` 隐藏已停驻的非末尾页面;App 把全局 DebugFab 排在路由 children 后面,使当前页也被命中。将全局 DebugFab 移到路由 children 前面,保持当前页位于最后,恢复首页及返回导航后的显示,无需覆盖路由 CSS。
|
||||||
|
|
||||||
|
H5 支持用 `TARO_H5_PORT` 指定开发端口(默认仍为 10086)。`TARO_H5_TEST_URL=http://localhost:10087 pnpm --filter @nomadro/miniprogram-h5 test:home` 已在 Chromium 的 390×844、1440×900 视口通过:首页可见、全局调试按钮可见、导航跳转和返回后页面可见、无 JavaScript 运行异常。浏览器回归模拟 API 故障以验证离线可见性,不写生产数据。另直接访问未模拟 API 的 10087 首页确认可见。
|
||||||
92
tests/platform.test.cjs
Normal file
92
tests/platform.test.cjs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// Exercise TypeScript sources without adding a second application bundler.
|
||||||
|
const { readFileSync } = require('node:fs');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const { test } = require('node:test');
|
||||||
|
const ts = require('typescript');
|
||||||
|
require.extensions['.ts'] = (module, filename) => {
|
||||||
|
const { outputText } = ts.transpileModule(readFileSync(filename, 'utf8'), {
|
||||||
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020, esModuleInterop: true },
|
||||||
|
fileName: filename,
|
||||||
|
});
|
||||||
|
module._compile(outputText, filename);
|
||||||
|
};
|
||||||
|
const { createNomadroClient } = require('../packages/sdk/src/client.ts');
|
||||||
|
const { resolvePayProvider } = require('../packages/pay/src/index.ts');
|
||||||
|
const { publicCors } = require('../src/lib/public-api/http.ts');
|
||||||
|
const tools = require('../packages/sdk/tools.json');
|
||||||
|
|
||||||
|
test('all SDK and MCP tools follow the tool catalog, including detached SDK calls', async () => {
|
||||||
|
const { callTool: mcpCallTool } = await import('../packages/mcp/src/server.mjs');
|
||||||
|
for (const tool of tools) {
|
||||||
|
const calls = [];
|
||||||
|
const mockFetch = async (url, init) => {
|
||||||
|
calls.push({ url: new URL(url), init });
|
||||||
|
return Response.json({ ok: true });
|
||||||
|
};
|
||||||
|
const args = Object.fromEntries(Object.entries(tool.inputSchema.properties).map(([key, spec]) =>
|
||||||
|
[key, spec.type === 'number' ? 3 : 'value /中文']));
|
||||||
|
const { callTool } = createNomadroClient({ fetch: mockFetch });
|
||||||
|
assert.deepEqual(await callTool(tool.name, args), { ok: true });
|
||||||
|
assert.deepEqual(await mcpCallTool(tool.name, args, mockFetch), { ok: true });
|
||||||
|
for (const { url, init } of calls) {
|
||||||
|
assert.equal(init.method, tool.method);
|
||||||
|
assert.ok(init.signal instanceof AbortSignal);
|
||||||
|
const expectedPath = tool.path.replace(/\{(\w+)\}/g, (_, key) => encodeURIComponent(args[key]));
|
||||||
|
assert.equal(url.pathname, `/api/public/v1${expectedPath}`);
|
||||||
|
for (const key of [...tool.path.matchAll(/\{(\w+)\}/g)].map(match => match[1])) {
|
||||||
|
assert.equal(url.searchParams.has(key), false);
|
||||||
|
if (init.body) assert.equal(key in JSON.parse(init.body), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('SDK and MCP reject malformed success responses and preserve HTTP errors', async () => {
|
||||||
|
const { callTool } = await import('../packages/mcp/src/server.mjs');
|
||||||
|
for (const body of ['<html>upstream error</html>', 'null', '[]', '42']) {
|
||||||
|
const fetch = async () => new Response(body);
|
||||||
|
await assert.rejects(createNomadroClient({ fetch }).health(), /Invalid JSON object/);
|
||||||
|
await assert.rejects(callTool('health', {}, fetch), /Invalid JSON object/);
|
||||||
|
}
|
||||||
|
const fetch = async () => new Response('null', { status: 503 });
|
||||||
|
await assert.rejects(createNomadroClient({ fetch }).health(), error => error.status === 503 && error.message === 'HTTP 503');
|
||||||
|
await assert.rejects(callTool('health', {}, fetch), /HTTP 503/);
|
||||||
|
const denied = async () => Response.json({ detail: 'denied' }, { status: 403 });
|
||||||
|
await assert.rejects(createNomadroClient({ fetch: denied }).health(), error => error.status === 403 && error.data.detail === 'denied');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('SDK timeout cancels stalled requests and writes are never retried', async () => {
|
||||||
|
let requests = 0;
|
||||||
|
const fetch = async (_, { signal }) => {
|
||||||
|
requests++;
|
||||||
|
return new Promise((resolve, reject) => signal.addEventListener('abort', () => reject(signal.reason), { once: true }));
|
||||||
|
};
|
||||||
|
// Keep the test process alive while AbortSignal.timeout uses its unref timer.
|
||||||
|
const keepAlive = setTimeout(() => {}, 1000);
|
||||||
|
try {
|
||||||
|
await assert.rejects(createNomadroClient({ fetch, timeoutMs: 10 }).applyGig({ gigId: 'x', name: 'a', contact: 'b' }), { name: 'TimeoutError' });
|
||||||
|
assert.equal(requests, 1);
|
||||||
|
} finally { clearTimeout(keepAlive); }
|
||||||
|
for (const timeoutMs of [0, -1, NaN, Infinity]) {
|
||||||
|
assert.throws(() => createNomadroClient({ timeoutMs }), /timeoutMs/);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('explicit audience overrides conflicting detection hints in payment routing', () => {
|
||||||
|
assert.equal(resolvePayProvider({ audience: 'cn', isChinaUser: false, userAgent: 'desktop' }).provider, 'zpay');
|
||||||
|
assert.equal(resolvePayProvider({ audience: 'intl', isChinaUser: true }).provider, 'creem');
|
||||||
|
assert.equal(resolvePayProvider({ audience: 'cn', userAgent: 'MicroMessenger' }).provider, 'xpay');
|
||||||
|
assert.equal(resolvePayProvider({ region: 'overseas', audience: 'cn' }).provider, 'creem');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('public CORS accepts real HTTP origins and rejects suffix spoofing and malformed origins', () => {
|
||||||
|
for (const origin of ['https://nomadro.com', 'https://admin.nomadro.cn', 'http://localhost:3000', 'https://sub.nomadro.com:8443']) {
|
||||||
|
const headers = publicCors({ headers: new Headers({ origin }) });
|
||||||
|
assert.equal(headers['Access-Control-Allow-Origin'], origin);
|
||||||
|
}
|
||||||
|
for (const origin of ['https://evilnomadro.com', 'https://nomadro.com.evil.test', 'https://evil.test/path.nomadro.com', 'ftp://sub.nomadro.com', 'null']) {
|
||||||
|
const headers = publicCors({ headers: new Headers({ origin }) });
|
||||||
|
assert.equal(headers['Access-Control-Allow-Origin'], undefined);
|
||||||
|
assert.equal(headers.Vary, 'Origin');
|
||||||
|
}
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user