fix(motion): 站内跳转白屏——路由内容不再走 AnimatePresence wait 退场

现象:生产环境所有站内跳转白屏,地址与标题已切换,刷新才恢复。
根因: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。
This commit is contained in:
zhangxiang committed 2026-10-20 14:00:41 +08:00
1 parent 092ed385b0
commit 2f86c4419a
7 files changed
+167 -54

No files matched your search

+9 -3
View File
@@ -48,14 +48,20 @@ export default function MarketingTemplate({
// 2026-10-20:**不再早返回 `<>{children}</>`** —— 那会让树结构与 SSR 不同
// (服务端永远渲染 motion.div,客户端 reduce 用户渲染裸 Fragment)⇒ React #418。
// 改为结构恒定,只在挂载后把 variants 换成空组(时长 0、无位移)。
// 2026-10-20(导航白屏修复的连带回归):reduce 变体不能写成 `{}`。motion.div 挂载时
// hook 仍是 false(首帧与 SSR 一致),它按 pageVariants 开始 0→1 的入场;effect 切到
// reduce 后 `animate="enter"` 若映射到空变体,framer 会停在当前帧(实测 opacity 0.2)
// 而不是「一步到位」。改为显式给可见终值 + 0 时长。
const variants = shouldReduceMotion
? { initial: {}, enter: {}, exit: {} }
? {
initial: { opacity: 1, y: 0 },
enter: { opacity: 1, y: 0, transition: { duration: 0 } },
}
: pageVariants;
return (
<motion.div
initial="initial"
initial={shouldReduceMotion ? false : 'initial'}
animate="enter"
exit="exit"
variants={variants}