现象:生产环境所有站内跳转白屏,地址与标题已切换,刷新才恢复。
根因:AnimatePresence mode="wait" 要求新页等旧页退场完成才挂载;App Router
导航期间的重复渲染会重置退场完成标记,切换 state 的窗口被错过,
motion.div 永久停在 exit 变体(opacity:0; translateY(-8px))。
修法:路由内容只保留 key={pathname} 的 280ms 入场;首屏仍由 mounted 渲染
裸 children;reduce 变体改为显式可见终值,避免切到空变体时冻结在半透明。
守卫:新增 client-navigation-visibility(导航后落定再读祖先链乘积);
首屏用例改逐帧采样;视觉用例改逐屏滚动触发 whileInView。
验证:E2E 20/20(四浏览器)、视觉 125/125、单测 1815、type-check/lint 0 error。
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
import { test, expect } from './fixtures';
|
||
|
||
/**
|
||
* 客户端导航可见性回归(2026-10-20 生产白屏)。
|
||
*
|
||
* 缺陷原型:首页点击导航后 URL 与正文都已切换,但 PageTransition 的 motion.div 停在
|
||
* exit 变体(inline opacity:0; translateY(-8px)),新页面永不进入 ⇒ 整页白屏,刷新才恢复。
|
||
* 只看 h1 自身 opacity 读不到(恒为 1),必须读祖先链的乘积累积。
|
||
*
|
||
* 复核:`E2E_TARGET=production npx playwright test client-navigation-visibility`。
|
||
*/
|
||
const NAV_STEPS = [
|
||
{ href: '/about', label: '关于我们' },
|
||
{ href: '/products', label: '产品矩阵' },
|
||
{ href: '/methodology', label: '方法论' },
|
||
{ href: '/insights', label: '洞察' },
|
||
{ href: '/about/brand', label: '品牌故事' },
|
||
];
|
||
|
||
function effectiveOpacity(page: import('@playwright/test').Page) {
|
||
return page.evaluate(() => {
|
||
const main = document.querySelector('main#main-content');
|
||
let opacity = 1;
|
||
let node: Element | null = main;
|
||
while (node) {
|
||
opacity *= Number(getComputedStyle(node).opacity);
|
||
node = node.parentElement;
|
||
}
|
||
return opacity;
|
||
});
|
||
}
|
||
|
||
test('首页经客户端导航到各栏目后内容必须可见', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'networkidle', timeout: 60000 });
|
||
await expect
|
||
.poll(() => effectiveOpacity(page), { timeout: 15000 })
|
||
.toBeGreaterThan(0.99);
|
||
|
||
for (const step of NAV_STEPS) {
|
||
await page.getByTestId('footer').locator(`a[href="${step.href}"]`).first().click();
|
||
await page.waitForURL(`**${step.href}`, { timeout: 15000 });
|
||
// 退场 200ms + 入场 280ms 都在 URL 变化之后才落定;URL 一变就采样会读到退场前的 1(假绿)。
|
||
await page.waitForTimeout(800);
|
||
|
||
await expect
|
||
.poll(() => effectiveOpacity(page), {
|
||
timeout: 5000,
|
||
message: `导航到 ${step.href}(${step.label})后整页有效 opacity 未回到 1(白屏)`,
|
||
})
|
||
.toBeGreaterThan(0.99);
|
||
}
|
||
});
|