diff --git a/docs/acceptance/2026-10-20-prod-about/about-cold-after-fix.png b/docs/acceptance/2026-10-20-prod-about/about-cold-after-fix.png new file mode 100644 index 0000000..87c0cc2 Binary files /dev/null and b/docs/acceptance/2026-10-20-prod-about/about-cold-after-fix.png differ diff --git a/docs/acceptance/2026-10-20-prod-about/contact-cold.png b/docs/acceptance/2026-10-20-prod-about/contact-cold.png new file mode 100644 index 0000000..a04b989 Binary files /dev/null and b/docs/acceptance/2026-10-20-prod-about/contact-cold.png differ diff --git a/docs/acceptance/2026-10-20-prod-about/probe-cold-first.mjs b/docs/acceptance/2026-10-20-prod-about/probe-cold-first.mjs new file mode 100644 index 0000000..5c9aad1 --- /dev/null +++ b/docs/acceptance/2026-10-20-prod-about/probe-cold-first.mjs @@ -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(); diff --git a/docs/acceptance/2026-10-20-prod-about/probe-cold-multi.mjs b/docs/acceptance/2026-10-20-prod-about/probe-cold-multi.mjs new file mode 100644 index 0000000..a085112 --- /dev/null +++ b/docs/acceptance/2026-10-20-prod-about/probe-cold-multi.mjs @@ -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(); diff --git a/docs/acceptance/2026-10-20-prod-about/probe-contact.mjs b/docs/acceptance/2026-10-20-prod-about/probe-contact.mjs new file mode 100644 index 0000000..3f84b46 --- /dev/null +++ b/docs/acceptance/2026-10-20-prod-about/probe-contact.mjs @@ -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(); diff --git a/docs/acceptance/2026-10-20-prod-about/probe-opacity-chain.mjs b/docs/acceptance/2026-10-20-prod-about/probe-opacity-chain.mjs new file mode 100644 index 0000000..b298518 --- /dev/null +++ b/docs/acceptance/2026-10-20-prod-about/probe-opacity-chain.mjs @@ -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(); diff --git a/docs/acceptance/qa-tracker.md b/docs/acceptance/qa-tracker.md index c8ea51a..73d1bab 100644 --- a/docs/acceptance/qa-tracker.md +++ b/docs/acceptance/qa-tracker.md @@ -1275,3 +1275,23 @@ webkit/mobile 的 Tab 引擎差异取证法、`pollBoundingBox` 的二次读取 于是**用旧文件重建了一次镜像**(容器 healthy、页面正常,所以没有症状)。 发现后改成显式命令重传并重建,并以 BUILD_ID 与 reduce 实测确认线上真是新代码。 ⇒ 同 §5.44 的教训:**"命令都返回了"不等于"命令都成功了"**;批量 rsync 必须逐条判退出码。 + +### 16.6 白屏的两个真因都修掉了,并补上"发布后必须预热" + +用户补充「首次访问白屏,需要刷新才可以」后,用**禁用缓存 + 限速**做冷首访复现,量出两条独立成因: + +| 成因 | 证据 | 修法 | 修后读数 | +|---|---|---|---| +| ① 首屏可见性依赖 JS:全站 167 处 framer 入场把初始 opacity 内联成 0 | 745ms 时 HTML 已在(正文 1177 字)但 h1 `opacity=0`,5945ms 才变 1 | `globals.css` 的 `html:not([data-content-ready])` 兜底(JS 未就绪前强制可见)+ 营销页 template 水合后 800ms 置位交还 framer;JS 永不执行则一直可见 | `/about` 冷首访 h1 可见 **5.9s → 1.65s** | +| ② `/contact` 因 `useSearchParams()` 在客户端组件里被**预渲染成 Suspense fallback**(只显示「加载中…」) | 冷首访 6s 才出现 h1;SSR HTML 里 h1 只在 RSC payload 里,DOM 迟迟没有 | 该参数只用于一次性成功提示 ⇒ 改为挂载后从 `window.location` 读并 `replaceState` 清理;页面恢复完整预渲染 | 冷首访 h1 可见 **6.0s → 1.5s**;HTML 含内容(73KB) | +| ③ 冷 ISR/构建后首访的生成延迟(叠加放大①②) | 30 条路由首访 0.3–0.9s,第二遍普遍 HIT、<400ms | 新增 `scripts/ops/warm-routes.mjs`:发布后按 sitemap 逐条预热并断言全 200、第二遍 >1500ms 记为异常 | 第二遍:非 200 **0**、>1500ms **0** | + +**全站冷首访复测(禁用缓存 + 900kbps)**:`/ 827ms`、`/about 1652ms`、`/contact 1511ms`、 +`/products 917ms`、`/services/software 922ms`、`/insights 1532ms`。 + +**发布过程中另一起事故(已处置)**:第三次重建镜像时服务器 **磁盘 99%(剩 353M)**, +`COPY dist/standalone` 报 `no space left on device`,`BUILD_EXIT=1` 而 `up -d` 仍执行(容器继续跑旧镜像)。 +处置:删掉最老三代 `dist_backup_*`(1.8G)与两个中间态、`docker image prune -f`(1.075G), +磁盘回到 **81%(3.9G 可用)**;重建成功(镜像 `015b6d75`)、容器 healthy。 +⚠ 连带纪律:**`docker-compose build` 失败后不能接着 `up -d`**(那只是重启旧镜像,会伪装成"已发布"); +runbook 已加"构建失败即中止"与"发布前检查磁盘 ≥2G"。 diff --git a/docs/development/deploy-runbook.md b/docs/development/deploy-runbook.md index 919d2ad..df4cc73 100644 --- a/docs/development/deploy-runbook.md +++ b/docs/development/deploy-runbook.md @@ -4,6 +4,14 @@ > 不要带着已知漂移往下走。生产侧的实测事实见 `reference-production-server-deploy` 记忆与 > `docs/acceptance/qa-tracker.md` §12–§14。 +## 0. 发布前硬件检查 + +```bash +ssh root@139.155.109.62 "df -h / | tail -1" +# 要求可用 ≥ 2G(2026-10-20 真实踩过:99% 满时 COPY 报 no space left on device, +# 而 up -d 仍会跑起来 → 旧镜像被当成"已发布")。备份保留最近 2 代即可。 +``` + ## 0. 这次发布包含什么(dev tip `8799a965` 起) - §11 对标语法批(首页 8 段、双轴 IA、信任层零编造、tracer-bullet 详情页) @@ -87,6 +95,9 @@ rsync -az dist/static/ root@…:/home/novalon/docker-app/novalon-website/dist/_n rsync -az public/ root@…:/home/novalon/docker-app/novalon-website/public/ rsync -az public/ root@…:/home/novalon/docker-app/novalon-website/dist/ # 根级静态资产 # 3) 重建镜像并重启(compose 是 v1 ⇒ docker-compose) +# ⚠ 构建失败必须中止:把 build 与 up 串成一条 `&&` 链,别让 up 在 build 失败后继续跑。 +# 2026-10-20 踩过:ENOSPC 导致 COPY 失败,而 up -d 仍执行 ⇒ 容器跑旧镜像、看起来像已发布。 +# 判据:`BUILD_EXIT=0` 才允许 up;随后用 `docker inspect … {{.Image}}` 与 BUILD_ID 复核。 ssh root@… 'cd /home/novalon/docker-app/novalon-website \ && docker-compose -f docker-compose.server.yml build novalon-website \ && docker-compose -f docker-compose.server.yml up -d novalon-website' @@ -100,6 +111,10 @@ ssh root@… 'cd /home/novalon/docker-app/novalon-website \ ## 4. 发布后核对(全部只读) ```bash +# 4.0 预热 ISR(发布后立刻做;冷首访白屏的成因之一) +node scripts/ops/warm-routes.mjs --base https://www.novalon.cn +# 期望:第二遍全部 HIT 或 <1500ms;任何非 200 退出 1 + # 4.1 页面健康 + 关键页面状态码 for u in / /products /products/erp /solutions /solutions/manufacturing /services /insights /news /contact; do curl -s -o /dev/null -w "%{http_code} $u\n" https://www.novalon.cn$u; done diff --git a/scripts/ops/warm-routes.mjs b/scripts/ops/warm-routes.mjs new file mode 100755 index 0000000..2e49099 --- /dev/null +++ b/scripts/ops/warm-routes.mjs @@ -0,0 +1,42 @@ +#!/usr/bin/env node +/** + * 发布后 ISR 预热(2026-10-20,冷首访白屏的第二个真因)。 + * + * 现象:/contact 首访 6s 才出现 h1,而 SSR HTML 里本来就有 h1 + * ⇒ 不是客户端渲染问题,是**冷 ISR 生成**(缓存 MISS 时同步渲染、首访干等), + * 刷新命中刚生成的缓存所以「刷新就好」。 + * + * 用法:node scripts/ops/warm-routes.mjs [--base https://www.novalon.cn] [--concurrency 3] + * 判据:每条路由 200 且最终 x-nextjs-cache 命中(HIT)或 TTFB 明显下降; + * 有任何非 200 退出 1(预热不能"跑完就算成功")。 + */ +const arg = (n, d) => { const i = process.argv.indexOf(n); return i > 0 ? process.argv[i + 1] : d; }; +const BASE = arg('--base', 'https://www.novalon.cn'); +const CONC = Number(arg('--concurrency', '3')); + +const sitemap = await fetch(`${BASE}/sitemap.xml`).then((r) => r.text()).catch(() => ''); +let routes = [...sitemap.matchAll(/([^<]+)<\/loc>/g)].map((m) => new URL(m[1]).pathname); +routes = [...new Set(routes.length ? routes : ['/', '/about', '/contact', '/products', '/services', '/solutions', '/insights', '/news', '/cases'])]; + +async function hit(path) { + const t0 = Date.now(); + const r = await fetch(BASE + path, { headers: { 'cache-control': 'no-cache' } }).catch(() => null); + const ms = Date.now() - t0; + return { path, status: r?.status ?? 0, ms, cache: r?.headers.get('x-nextjs-cache') ?? '-' }; +} + +const first = []; +let i = 0; +await Promise.all(Array.from({ length: CONC }, async () => { + while (i < routes.length) { const p = routes[i++]; first.push(await hit(p)); } +})); +const second = []; +for (const r of routes) second.push(await hit(r)); + +const fmt = (rows) => rows.map((r) => `${String(r.status)} ${String(r.ms).padStart(5)}ms ${String(r.cache).padEnd(5)} ${r.path}`).join('\n'); +console.log(`== 第一遍(触发 ISR 生成)==\n${fmt(first)}`); +console.log(`\n== 第二遍(应命中缓存)==\n${fmt(second)}`); +const bad = [...first, ...second].filter((r) => r.status !== 200); +const slow = second.filter((r) => r.ms > 1500); +console.log(`\n汇总:路由 ${routes.length} · 非 200 ${bad.length} · 第二遍仍 >1500ms ${slow.length}`); +if (bad.length) process.exit(1); diff --git a/src/app/(marketing)/contact/contact-content-v3.tsx b/src/app/(marketing)/contact/contact-content-v3.tsx index af73118..b003f18 100644 --- a/src/app/(marketing)/contact/contact-content-v3.tsx +++ b/src/app/(marketing)/contact/contact-content-v3.tsx @@ -1,7 +1,6 @@ 'use client'; import { useState, useEffect, Suspense } from 'react'; -import { useSearchParams } from 'next/navigation'; import { z } from 'zod'; import { motion } from 'framer-motion'; import { Button } from '@/components/ui/button'; @@ -78,16 +77,16 @@ interface ContactData { } function ContactFormContent({ data }: { data: ContactData }) { - const searchParams = useSearchParams(); - const isSuccessFromRedirect = searchParams.get('success') === 'true'; - const [showToast, setShowToast] = useState(isSuccessFromRedirect); - const [toastMessage, setToastMessage] = useState( - isSuccessFromRedirect ? '表单提交成功!我们会尽快与您联系。' : '' - ); + // 2026-10-20(冷首访白屏):不再用 `useSearchParams()`。 + // 它在客户端组件里会让本页在预渲染时**退化成 Suspense fallback**(首访只看到「加载中…」, + // 实测限速下 ~6s 才出现内容)。该参数只用于展示一次成功提示, + // 挂载后从 window.location 读即可,页面因此可以完整预渲染。 + const [showToast, setShowToast] = useState(false); + const [toastMessage, setToastMessage] = useState(''); // 初值仅在 ?success=true 重定向时随 showToast/isSubmitted 一同生效,故恒为 success。 const [toastType, setToastType] = useState<'success' | 'error'>('success'); const [isSubmitting, setIsSubmitting] = useState(false); - const [isSubmitted, setIsSubmitted] = useState(isSuccessFromRedirect); + const [isSubmitted, setIsSubmitted] = useState(false); const [formData, setFormData] = useState({ name: '', phone: '', @@ -97,13 +96,17 @@ function ContactFormContent({ data }: { data: ContactData }) { }); const [errors, setErrors] = useState({}); - // 刷新不应重放成功态:读取 ?success=true 后立即从 URL 中移除 + // 成功重定向:挂载后读一次 ?success=true,应用成功态并立即从 URL 移除(刷新不应重放) useEffect(() => { - if (!isSuccessFromRedirect) return; + if (typeof window === 'undefined') return; + if (new URLSearchParams(window.location.search).get('success') !== 'true') return; + setShowToast(true); + setToastMessage('表单提交成功!我们会尽快与您联系。'); + setIsSubmitted(true); const url = new URL(window.location.href); url.searchParams.delete('success'); window.history.replaceState(null, '', url.pathname + url.search + url.hash); - }, [isSuccessFromRedirect]); + }, []); const emailAddress = data.email ?? ''; const addressText = data.address ?? '';