fix(motion): reduce 偏好下 hydration 不匹配(React #418)且元素停在 opacity:0
线上 /about 白屏排查(§16):30 条路由 + 6 种环境里唯一可复现的缺陷是 webkit/chromium + prefers-reduced-motion:reduce ⇒ pageerror #418,main 内 14 个元素 opacity 恒 0(正常环境只有 3 个首屏以下的滚动入场项)。 根因:useReducedMotion 用 window.matchMedia 作 useState 初值 ⇒ SSR false、客户端首帧 true; scroll-reveal / template / page-transition 又用它决定 initial/variants/甚至早返回不同树结构, 与 SSR HTML 不一致;且 reduce 时 whileInView 被清空 ⇒ 元素停在 initial 的 opacity:0。 修法(结构恒定,减少动效改用「时长 0」表达): - hook 首帧恒 false,挂载后 effect 同步真实偏好; - ScrollReveal/StaggerReveal 的 initial/whileInView/variants 不再按 reduce 清空; - template.tsx 与 StaggerChildren 去掉早返回裸结构,改空 variants。 回归守卫 e2e/reduced-motion-hydration.spec.ts(/about 与 /):断言 reduce 自证生效、 无 hydration 错误、h1 与末段标题 opacity=1。变异验证:hook 改回 matchMedia 初值 ⇒ 2 红,恢复 ⇒ 2 绿。 另:runbook 明确禁止对 dist/_next/static 用 --delete(回访者旧 HTML 会引用上一代 chunk); 本轮已从备份 --ignore-existing 合并回旧代 101 个文件。复算:tsc/type-check:e2e 0、 jest 35 套件 462 例 0、check:visual 0、check:motion 0、视觉 chromium-desktop 25/25。
This commit was merged in pull request #46.
This commit is contained in:
1 parent
524c1b6575
commit
d0090cea56
20 files changed
+341
-22
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 527 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 155 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 310 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 365 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 678 KiB |
@@ -0,0 +1,28 @@
|
||||
import { chromium } from 'playwright';
|
||||
const sm = await fetch('https://www.novalon.cn/sitemap.xml').then(r=>r.text()).catch(()=> '');
|
||||
let routes = [...sm.matchAll(/<loc>([^<]+)<\/loc>/g)].map(m=>new URL(m[1]).pathname);
|
||||
routes = [...new Set(['/about','/about/brand', ...routes])];
|
||||
const b = await chromium.launch();
|
||||
const ctx = await b.newContext({ viewport:{width:1280,height:900} });
|
||||
const p = await ctx.newPage();
|
||||
const rows = [];
|
||||
for (const r of routes.slice(0, 40)) {
|
||||
const errs = [];
|
||||
const onErr = e => errs.push(String(e).slice(0,120));
|
||||
p.on('pageerror', onErr);
|
||||
const resp = await p.goto('https://www.novalon.cn'+r, { waitUntil:'networkidle', timeout:60000 }).catch(()=>null);
|
||||
await p.waitForTimeout(700);
|
||||
const info = await p.evaluate(() => ({
|
||||
text: (document.querySelector('main')?.innerText ?? document.body.innerText ?? '').trim().length,
|
||||
mainH: Math.round(document.querySelector('main')?.getBoundingClientRect().height ?? -1),
|
||||
h1: document.querySelector('h1')?.innerText?.trim().slice(0,18) ?? null,
|
||||
hidden: [...document.querySelectorAll('main *')].filter(e=>parseFloat(getComputedStyle(e).opacity)===0).length,
|
||||
}));
|
||||
rows.push({ r, status: resp?.status() ?? 'ERR', ...info, errs: errs.length });
|
||||
p.off('pageerror', onErr);
|
||||
}
|
||||
await b.close();
|
||||
const bad = rows.filter(x => x.status !== 200 || x.text < 200 || x.mainH < 300 || x.errs > 0);
|
||||
console.log(`探测 ${rows.length} 条路由 · 异常 ${bad.length} 条`);
|
||||
for (const x of bad) console.log(' ⚠', JSON.stringify(x));
|
||||
console.log('正常样例:', JSON.stringify(rows.slice(0,3)));
|
||||
@@ -0,0 +1,30 @@
|
||||
import { chromium } from 'playwright';
|
||||
const b = await chromium.launch();
|
||||
const ctx = await b.newContext({ viewport:{width:1280,height:900} });
|
||||
const p = await ctx.newPage();
|
||||
const errs = [], cerr = [], failed = [], bad = [];
|
||||
p.on('pageerror', e => errs.push(String(e).slice(0,300)));
|
||||
p.on('console', m => { if (m.type()==='error') cerr.push(m.text().slice(0,220)); });
|
||||
p.on('requestfailed', r => failed.push(`${r.failure()?.errorText} ${r.url().slice(0,120)}`));
|
||||
p.on('response', r => { if (r.status() >= 400) bad.push(`${r.status()} ${r.url().slice(0,120)}`); });
|
||||
await p.goto('https://www.novalon.cn/', { waitUntil:'networkidle', timeout:60000 });
|
||||
// 先关掉 Cookie 条(若挡住点击)
|
||||
await p.getByRole('button', { name: /拒绝非必要|仅必要|同意/ }).first().click({ timeout: 3000 }).catch(()=>{});
|
||||
const link = p.locator('[data-testid="desktop-navigation"] a[href="/about"]').first();
|
||||
await link.waitFor({ state:'visible', timeout:10000 });
|
||||
await link.click();
|
||||
await p.waitForTimeout(4000);
|
||||
const info = await p.evaluate(() => ({
|
||||
url: location.href, title: document.title,
|
||||
mainTextLen: (document.querySelector('main')?.innerText ?? '').trim().length,
|
||||
mainH: Math.round(document.querySelector('main')?.getBoundingClientRect().height ?? -1),
|
||||
h1: document.querySelector('h1')?.innerText?.slice(0,24) ?? null,
|
||||
hidden: [...document.querySelectorAll('main *')].filter(e=>parseFloat(getComputedStyle(e).opacity)===0).length,
|
||||
}));
|
||||
await p.screenshot({ path:'docs/acceptance/2026-10-20-prod-about/about-clientnav.png', fullPage:true });
|
||||
console.log(JSON.stringify(info, null, 1));
|
||||
console.log('pageerrors', JSON.stringify(errs));
|
||||
console.log('consoleErrors', JSON.stringify(cerr.slice(0,6)));
|
||||
console.log('failed', JSON.stringify(failed.slice(0,6)));
|
||||
console.log('http>=400', JSON.stringify(bad.slice(0,8)));
|
||||
await b.close();
|
||||
@@ -0,0 +1,41 @@
|
||||
import { chromium, webkit } from 'playwright';
|
||||
// A) 找出 SSR 阶段 opacity:0 的元素(首屏是否含 h1)
|
||||
const b1 = await chromium.launch();
|
||||
const c1 = await b1.newContext({ viewport: { width: 1280, height: 900 }, javaScriptEnabled: false });
|
||||
const p1 = await c1.newPage();
|
||||
await p1.goto('https://www.novalon.cn/about', { waitUntil: 'domcontentloaded', timeout: 60000 }).catch(()=>{});
|
||||
await p1.waitForTimeout(800);
|
||||
const hidden = await p1.evaluate(() => {
|
||||
const out = [];
|
||||
for (const el of document.querySelectorAll('main *')) {
|
||||
const cs = getComputedStyle(el);
|
||||
if (parseFloat(cs.opacity) === 0) {
|
||||
const r = el.getBoundingClientRect();
|
||||
out.push({ tag: el.tagName, cls: (el.className||'').toString().slice(0,60), text: (el.innerText||'').slice(0,30), top: Math.round(r.top), h: Math.round(r.height) });
|
||||
}
|
||||
}
|
||||
return out.slice(0, 24);
|
||||
});
|
||||
console.log('SSR 隐藏元素:', JSON.stringify(hidden, null, 1));
|
||||
await b1.close();
|
||||
|
||||
// B) WebKit 带 JS 渲染
|
||||
const b2 = await webkit.launch();
|
||||
const c2 = await b2.newContext({ viewport: { width: 1280, height: 900 } });
|
||||
const p2 = await c2.newPage();
|
||||
const errs = [], cerr = [];
|
||||
p2.on('pageerror', e => errs.push(String(e).slice(0,300)));
|
||||
p2.on('console', m => { if (m.type()==='error') cerr.push(m.text().slice(0,200)); });
|
||||
const r = await p2.goto('https://www.novalon.cn/about', { waitUntil: 'networkidle', timeout: 60000 }).catch(e=>{console.log('GOTO', e.message);return null;});
|
||||
await p2.waitForTimeout(2000);
|
||||
const info = await p2.evaluate(() => {
|
||||
const h1 = document.querySelector('h1'); const cs = h1 ? getComputedStyle(h1) : null;
|
||||
const r = h1?.getBoundingClientRect();
|
||||
return { status: document.readyState, bodyTextLen: (document.body.innerText||'').trim().length,
|
||||
h1: h1?.innerText?.slice(0,20), h1opacity: cs?.opacity, h1visible: !!r && r.height>0 && parseFloat(cs?.opacity||'1')>0,
|
||||
hiddenCount: [...document.querySelectorAll('main *')].filter(e=>parseFloat(getComputedStyle(e).opacity)===0).length };
|
||||
});
|
||||
await p2.screenshot({ path: 'docs/acceptance/2026-10-20-prod-about/about-webkit.png', fullPage: true });
|
||||
console.log('webkit status', r?.status(), JSON.stringify(info));
|
||||
console.log('webkit pageerrors', JSON.stringify(errs), 'consoleErrors', JSON.stringify(cerr.slice(0,5)));
|
||||
await b2.close();
|
||||
@@ -0,0 +1,36 @@
|
||||
import { chromium, webkit, devices } from 'playwright';
|
||||
const cases = [
|
||||
['chromium-mobile', chromium, { ...devices['iPhone 14'] }],
|
||||
['webkit-mobile', webkit, { ...devices['iPhone 14'] }],
|
||||
['webkit-reduced-motion', webkit, { viewport:{width:1280,height:900}, reducedMotion:'reduce' }],
|
||||
['chromium-dark', chromium, { viewport:{width:1280,height:900}, colorScheme:'dark' }],
|
||||
['chromium-3g', chromium, { viewport:{width:1280,height:900} }],
|
||||
];
|
||||
for (const [name, engine, opts] of cases) {
|
||||
const b = await engine.launch();
|
||||
const ctx = await b.newContext(opts);
|
||||
const p = await ctx.newPage();
|
||||
const errs = [], cerr = [], failed = [];
|
||||
p.on('pageerror', e => errs.push(String(e).slice(0,200)));
|
||||
p.on('console', m => { if (m.type()==='error') cerr.push(m.text().slice(0,160)); });
|
||||
p.on('requestfailed', r => failed.push(`${r.failure()?.errorText} ${r.url().slice(0,90)}`));
|
||||
if (name === 'chromium-3g') {
|
||||
const cdp = await ctx.newCDPSession(p);
|
||||
await cdp.send('Network.enable');
|
||||
await cdp.send('Network.emulateNetworkConditions', { offline:false, latency:400, downloadThroughput: 200*1024, uploadThroughput: 100*1024 });
|
||||
}
|
||||
const resp = await p.goto('https://www.novalon.cn/about', { waitUntil: 'networkidle', timeout: 90000 }).catch(e=>{console.log(name,'GOTO',e.message);return null;});
|
||||
await p.waitForTimeout(2500);
|
||||
const info = await p.evaluate(() => {
|
||||
const h1 = document.querySelector('h1'); const cs = h1 ? getComputedStyle(h1) : null;
|
||||
const r = h1?.getBoundingClientRect();
|
||||
return { bodyTextLen: (document.body.innerText||'').trim().length,
|
||||
h1visible: !!r && r.height>0 && parseFloat(cs?.opacity||'1')>0, h1opacity: cs?.opacity,
|
||||
hidden: [...document.querySelectorAll('main *')].filter(e=>parseFloat(getComputedStyle(e).opacity)===0).length,
|
||||
mainH: Math.round(document.querySelector('main')?.getBoundingClientRect().height ?? -1) };
|
||||
});
|
||||
console.log(name.padEnd(24), 'status', resp?.status(), JSON.stringify(info), 'errs', errs.length, 'cerr', cerr.length, 'failed', failed.length);
|
||||
if (errs.length) console.log(' pageerrors', JSON.stringify(errs.slice(0,2)));
|
||||
if (cerr.length) console.log(' console', JSON.stringify(cerr.slice(0,3)));
|
||||
await b.close();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { chromium, webkit } from 'playwright';
|
||||
for (const [name, engine] of [['chromium', chromium], ['webkit', webkit]]) {
|
||||
const b = await engine.launch();
|
||||
const ctx = await b.newContext({ viewport: { width: 1280, height: 900 }, javaScriptEnabled: false });
|
||||
const p = await ctx.newPage();
|
||||
await p.goto('https://www.novalon.cn/about', { waitUntil: 'domcontentloaded', timeout: 60000 }).catch(()=>{});
|
||||
await p.waitForTimeout(1500);
|
||||
const vis = await p.evaluate(() => {
|
||||
const els = [...document.querySelectorAll('main *')];
|
||||
let visibleText = 0, hidden = 0;
|
||||
for (const el of els) {
|
||||
const cs = getComputedStyle(el);
|
||||
if (parseFloat(cs.opacity) === 0) hidden++;
|
||||
if (el.children.length === 0 && (el.textContent||'').trim() && parseFloat(cs.opacity) > 0) visibleText++;
|
||||
}
|
||||
return { hiddenByOpacity: hidden, visibleLeafText: visibleText, bodyTextLen: (document.body.innerText||'').trim().length };
|
||||
});
|
||||
await p.screenshot({ path: `docs/acceptance/2026-10-20-prod-about/about-nojs-${name}.png`, fullPage: true });
|
||||
console.log(name, 'JS禁用:', JSON.stringify(vis));
|
||||
await b.close();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { webkit } from 'playwright';
|
||||
const b = await webkit.launch();
|
||||
const ctx = await b.newContext({ viewport:{width:1280,height:900}, reducedMotion:'reduce' });
|
||||
const p = await ctx.newPage();
|
||||
await p.goto('https://www.novalon.cn/about', { waitUntil:'networkidle', timeout:60000 }).catch(()=>{});
|
||||
await p.waitForTimeout(2500);
|
||||
await p.screenshot({ path:'docs/acceptance/2026-10-20-prod-about/about-reduced-motion.png', fullPage:true });
|
||||
const t = await p.evaluate(() => [...document.querySelectorAll('main *')].filter(e=>parseFloat(getComputedStyle(e).opacity)===0).map(e=>({tag:e.tagName, cls:(e.className||'').toString().slice(0,50), text:(e.innerText||'').slice(0,24)})));
|
||||
console.log('隐藏元素:', JSON.stringify(t, null, 1));
|
||||
await b.close();
|
||||
@@ -0,0 +1,26 @@
|
||||
import { chromium } from 'playwright';
|
||||
const url = process.argv[2] ?? 'https://www.novalon.cn/about';
|
||||
const b = await chromium.launch();
|
||||
const ctx = await b.newContext({ viewport: { width: 1280, height: 900 } });
|
||||
const p = await ctx.newPage();
|
||||
const consoleMsgs = [], pageErrors = [], failed = [];
|
||||
p.on('console', (m) => { if (['error','warning'].includes(m.type())) consoleMsgs.push(`${m.type()}: ${m.text()}`.slice(0, 300)); });
|
||||
p.on('pageerror', (e) => pageErrors.push(String(e).slice(0, 400)));
|
||||
p.on('requestfailed', (r) => failed.push(`${r.failure()?.errorText} ${r.url()}`.slice(0, 220)));
|
||||
const resp = await p.goto(url, { waitUntil: 'networkidle', timeout: 60000 }).catch((e) => { console.log('GOTO_ERR', e.message); return null; });
|
||||
await p.waitForTimeout(2000);
|
||||
const info = await p.evaluate(() => ({
|
||||
title: document.title,
|
||||
bodyTextLen: (document.body?.innerText ?? '').trim().length,
|
||||
bodyHtmlLen: document.body?.innerHTML.length ?? 0,
|
||||
mainLen: document.querySelector('main')?.innerHTML.length ?? -1,
|
||||
h1: [...document.querySelectorAll('h1')].map((h) => h.innerText.trim()).slice(0, 3),
|
||||
nextErr: !!document.querySelector('nextjs-portal, [data-nextjs-dialog]'),
|
||||
}));
|
||||
await p.screenshot({ path: 'docs/acceptance/2026-10-20-prod-about/about-live.png', fullPage: true });
|
||||
console.log('status', resp?.status());
|
||||
console.log(JSON.stringify(info, null, 1));
|
||||
console.log('pageErrors', JSON.stringify(pageErrors, null, 1));
|
||||
console.log('console', JSON.stringify(consoleMsgs.slice(0, 12), null, 1));
|
||||
console.log('failedRequests', JSON.stringify(failed.slice(0, 12), null, 1));
|
||||
await b.close();
|
||||
Reference in new issue
Block a user