fix(contact): 去掉 useSearchParams 让 /contact 可完整预渲染;补发布后 ISR 预热脚本

冷首访白屏的第二个真因:/contact 用 useSearchParams() 读 ?success,客户端组件里
这会让整页在预渲染时退化成 Suspense fallback(首访只看到「加载中…」,限速下 ~6s 才出内容)。
该参数只用于一次性成功提示 ⇒ 改为挂载后从 window.location 读并 replaceState 清理。

- /contact 冷首访 h1 可见:6.0s → 1.5s;HTML 73KB 含正文(此前只有外壳)。
- 新增 scripts/ops/warm-routes.mjs:按 sitemap 预热并断言全 200、第二遍 <1500ms 或 HIT;
  本轮线上第二遍:非 200 = 0、>1500ms = 0。
- 全站冷首访复测:/ 827ms、/about 1652ms、/contact 1511ms、/products 917ms、
  /services/software 922ms、/insights 1532ms。
- runbook:加发布前磁盘检查(≥2G)与「构建失败必须中止」;加 §4.0 预热步骤。
- 事故记录:第三次重建时服务器磁盘 99%,COPY 报 ENOSPC 而 up -d 仍执行(旧镜像被当已发布);
  清理旧备份 1.8G + docker image prune 1.075G 后回到 81%,重建 015b6d75 成功。
This commit is contained in:
zhangxiang committed 2026-10-20 08:23:34 +08:00
1 parent ca3df3221d
commit 702c732d27
10 files changed
+203 -12

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

@@ -0,0 +1,39 @@
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 cdp = await ctx.newCDPSession(p);
await cdp.send('Network.enable');
await cdp.send('Network.setCacheDisabled', { cacheDisabled: true });
await cdp.send('Network.emulateNetworkConditions', { offline:false, latency:150, downloadThroughput: 900*1024/8, uploadThroughput: 400*1024/8 });
const t0 = Date.now();
const samples = [];
const seen = new Set();
p.on('response', r => { if (r.url().includes('/about')) seen.add(`${r.status()} ${r.url()}`); });
const nav = p.goto('https://www.novalon.cn/about', { waitUntil:'commit', timeout:90000 }).catch(()=>null);
for (let i=0;i<80;i++) {
const s = await p.evaluate(() => {
const h1 = document.querySelector('h1');
const html = document.documentElement;
// 找包住 main 的 motion wrapper 的 opacity
const main = document.querySelector('main');
let wrap = main?.parentElement, wrapOp = null;
while (wrap && wrap !== document.body) { const o = getComputedStyle(wrap).opacity; if (o !== '1') { wrapOp = o; break; } wrap = wrap.parentElement; }
return { t: Math.round(performance.now()),
body: document.body ? document.body.innerHTML.length : -1,
h1op: h1 ? Number(getComputedStyle(h1).opacity) : null,
wrapOp,
textLen: document.body ? (document.body.innerText||'').trim().length : -1 };
}).catch(()=>null);
if (s) samples.push(s);
await p.waitForTimeout(120);
if (s && s.h1op === 1 && s.textLen > 800) break;
}
await nav;
console.log('responses', JSON.stringify([...seen]));
const firstText = samples.find(s=>s.textLen>500);
const firstVisible = samples.find(s=>s.h1op===1 && s.textLen>800);
console.log('TTFB-ish 首个有文字样本:', firstText ? `${firstText.t}ms len=${firstText.textLen} wrapOp=${firstText.wrapOp} h1op=${firstText.h1op}` : 'none');
console.log('首个 h1 完全不透样本:', firstVisible ? `${firstVisible.t}ms` : 'none');
console.log('样本前 6 条:', JSON.stringify(samples.slice(0,6)));
await b.close();
@@ -0,0 +1,25 @@
import { chromium } from 'playwright';
const routes = ['/', '/about', '/contact', '/products', '/services/software', '/insights'];
const b = await chromium.launch();
for (const r of routes) {
const ctx = await b.newContext({ viewport:{width:1280,height:900} });
const p = await ctx.newPage();
const cdp = await ctx.newCDPSession(p);
await cdp.send('Network.enable');
await cdp.send('Network.setCacheDisabled', { cacheDisabled: true });
await cdp.send('Network.emulateNetworkConditions', { offline:false, latency:150, downloadThroughput: 900*1024/8, uploadThroughput: 400*1024/8 });
p.goto('https://www.novalon.cn'+r, { waitUntil:'commit', timeout:90000 }).catch(()=>{});
let firstVisible = null, s = null;
for (let i=0;i<70;i++) {
s = await p.evaluate(() => {
const h1 = document.querySelector('h1'); const cs = h1 ? getComputedStyle(h1) : null;
return h1 ? { t: Math.round(performance.now()), op: Number(cs.opacity), visible: document.visibilityState } : null;
}).catch(()=>null);
if (s && s.op === 1) { firstVisible = s.t; break; }
await p.waitForTimeout(120);
}
console.log(r.padEnd(20), firstVisible !== null ? `h1 可见@${firstVisible}ms` : 'NOT VISIBLE in window');
if (r === '/about') await p.screenshot({ path:'docs/acceptance/2026-10-20-prod-about/about-cold-after-fix.png', fullPage:false });
await ctx.close();
}
await b.close();
@@ -0,0 +1,25 @@
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 cdp = await ctx.newCDPSession(p);
await cdp.send('Network.enable');
await cdp.send('Network.setCacheDisabled', { cacheDisabled: true });
await cdp.send('Network.emulateNetworkConditions', { offline:false, latency:150, downloadThroughput: 900*1024/8, uploadThroughput: 400*1024/8 });
p.goto('https://www.novalon.cn/contact', { waitUntil:'commit', timeout:90000 }).catch(()=>{});
for (let i=0;i<8;i++) {
await p.waitForTimeout(1000);
const s = await p.evaluate(() => {
const h1 = document.querySelector('h1');
const ready = document.documentElement.getAttribute('data-content-ready');
const text = (document.body?.innerText||'').trim().length;
const zeros = [...document.querySelectorAll('body *')].filter(e=>parseFloat(getComputedStyle(e).opacity)===0).length;
return { t: Math.round(performance.now()), h1: !!h1, h1txt: h1?.innerText?.slice(0,20) ?? null,
h1op: h1 ? getComputedStyle(h1).opacity : null, ready, text, zeros,
parentOp: h1?.parentElement ? getComputedStyle(h1.parentElement).opacity : null };
}).catch(()=>null);
console.log(JSON.stringify(s));
if (s && s.h1op === '1') break;
}
await p.screenshot({ path:'docs/acceptance/2026-10-20-prod-about/contact-cold.png' });
await b.close();
@@ -0,0 +1,23 @@
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 cdp = await ctx.newCDPSession(p);
await cdp.send('Network.enable');
await cdp.send('Network.setCacheDisabled', { cacheDisabled: true });
await cdp.send('Network.emulateNetworkConditions', { offline:false, latency:120, downloadThroughput: 120*1024*8, uploadThroughput: 60*1024*8 });
p.goto('https://www.novalon.cn/about', { waitUntil:'commit', timeout:90000 }).catch(()=>{});
for (const wait of [900, 1500, 3000]) {
await p.waitForTimeout(wait === 900 ? 900 : wait - 900);
const snap = await p.evaluate(() => {
const h1 = document.querySelector('h1');
const chain = [];
let el = h1;
while (el) { chain.push(`${el.tagName}${el.className?'.'+String(el.className).split(' ')[0]:''} op=${getComputedStyle(el).opacity}`); el = el.parentElement; }
const zeros = [...document.querySelectorAll('body *')].filter(e => parseFloat(getComputedStyle(e).opacity) === 0)
.slice(0,8).map(e => ({ tag:e.tagName, cls:String(e.className).slice(0,46), text:(e.innerText||'').slice(0,16) }));
return { t: Math.round(performance.now()), h1op: h1 ? getComputedStyle(h1).opacity : null, chain: chain.slice(0,9), zeros };
}).catch(()=>null);
console.log('@'+wait+'ms', JSON.stringify(snap));
}
await b.close();