;\n\nconst server = http.createServer((req, res) => {\n const url = new URL(req.url, 'http://x');\n const mode = url.searchParams.get('mode') || 'inline';\n const client = url.searchParams.get('client') || 'client.js';\n if (url.pathname.endsWith('.js')) { res.setHeader('content-type', 'text/javascript'); return res.end(fs.readFileSync('out' + url.pathname)); }\n if (url.pathname === '/route.css') {\n const css = renderRoute(url.searchParams.get('r')).css;\n return setTimeout(() => { res.setHeader('content-type', 'text/css'); res.end(css); }, CSS_DELAY_MS);\n }\n const r = renderRoute(url.pathname, { collect: !(BREAK && mode === 'inline') && mode !== 'none' });\n const head = mode === 'link' ? : r.tags;\n res.setHeader('content-type', 'text/html');\n res.end(page(r.html, head, client));\n});\nawait new Promise((r) => server.listen(0, r));\nconst base = http://127.0.0.1:${server.address().port};\nconst browser = await chromium.launch();\nconst fail = [];\n\n// 1. Styles arrive in the HTML: with JavaScript disabled, only server-delivered CSS can style the page.\nconst noJs = await browser.newContext({ javaScriptEnabled: false });\nconst bg = async (mode) => { const p = await noJs.newPage(); await p.goto(${base}/?mode=${mode}); \n const color = await p.locator('section').evaluate((el) => getComputedStyle(el).backgroundColor); await p.close(); return color; };\nconst withCss = await bg('inline'), without = await bg('none');\nconsole.log({ heroBackgroundInlineCss: withCss, heroBackgroundNoCss: without });\nif (withCss !== 'rgb(29, 78, 216)') fail.push(inline critical CSS did not style the hero: ${withCss});\n\n// 2. Per route: each route's CSS holds only its own components.\nconst home = renderRoute('/').css, pricing = renderRoute('/pricing').css;\nconst has = (css, s) => css.includes(s);\nconsole.log({ homeHasHero: has(home, '#1d4ed8'), homeHasPlans: has(home, '#7a1fa2'), pricingHasHero: has(pricing, '#1d4ed8'), pricingHasPlans: has(pricing, '#7a1fa2'), homeBytes: home.length, pricingBytes: pricing.length });\nif (!has(home, '#1d4ed8') || has(home, '#7a1fa2')) fail.push('home CSS has the wrong components');\nif (!has(pricing, '#7a1fa2') || has(pricing, '#1d4ed8')) fail.push('pricing CSS has the wrong components');\n\n// 3. Hydration: no console errors, the button works, and the CSS is not injected twice.\nasync function hydrate(client) {\n const p = await browser.newPage(); const msgs = [];\n p.on('console', (m) => { if (['error', 'warning'].includes(m.type())) msgs.push(m.text()); });\n await p.goto(${base}/?client=${client});\n await p.waitForFunction(() => window.__hydrated === true);\n await p.click('button'); const label = await p.textContent('button');\n const styleTags = await p.evaluate(() => document.querySelectorAll('style[data-styled]').length);\n await p.close(); return { msgs, label, styleTags };\n}\nconst good = await hydrate('client.js'), decoy = await hydrate('client-decoy.js');\nconsole.log(decoy.msgs.find((m) => /did not match/.test(m))?.split('\\n')[0]);\nconsole.log({ goodMessages: good.msgs.length, goodLabel: good.label, goodStyleTags: good.styleTags,\n decoyMismatchWarnings: decoy.msgs.filter((m) => /did not match/.test(m)).length });\nif (good.msgs.length) fail.push('hydration produced console messages: ' + good.msgs[0].slice(0, 120));\nif (good.label !== 'Clicked 1') fail.push('hydrated button did not respond');\nif (!decoy.msgs.some((m) => /did not match/.test(m))) fail.push('expected the creation-order mismatch to warn');\n\n// 4. Cost of a render-blocking stylesheet versus inline: first-contentful-paint.\nasync function fcp(mode) {\n const ctx = await browser.newContext(); const p = await ctx.newPage();\n await p.goto(${base}/?mode=${mode});\n const v = await p.evaluate(() => new Promise((r) => new PerformanceObserver((l, o) => {\n const e = l.getEntriesByName('first-contentful-paint')[0]; if (e) { o.disconnect(); r(e.startTime); } }).observe({ type: 'paint', buffered: true })));\n await ctx.close(); return v;\n};\nconst fi = await fcp('inline'), fl = await fcp('link');\nconsole.log({ fcpInlineMs: Math.round(fi), fcpLinkedMs: Math.round(fl), stylesheetDelayMs: CSS_DELAY_MS });\nif (fl - fi < CSS_DELAY_MS * 0.6) fail.push(linked stylesheet only cost ${Math.round(fl - fi)} ms);\n\n// 5. Cache: renders happen once per route and build.\nconst before = { ...stats };\nfor (let i = 0; i < 5; i++) renderRoute('/'), renderRoute('/pricing');\nconsole.log({ rendersAdded: stats.renders - before.renders, hitsAdded: stats.hits - before.hits });\nif (stats.renders - before.renders !== 0) fail.push('cache missed');\n\nawait browser.close(); server.close();\nif (fail.length) { console.error('FAIL\\n' + fail.join('\\n')); process.exit(1); }\nconsole.log('PASS');\n\nRun in a mcr.microsoft.com/playwright:v1.48.2-jammy container (Chromium 130.0.6723.31, headless, Linux), one sample run prints the lines below (the FCP line varies from run to run):\n\n{\n heroBackgroundInlineCss: 'rgb(29, 78, 216)',\n heroBackgroundNoCss: 'rgba(0, 0, 0, 0)'\n}\n{\n homeHasHero: true,\n homeHasPlans: false,\n pricingHasHero: false,\n pricingHasPlans: true,\n homeBytes: 378,\n pricingBytes: 251\n}\nWarning: Prop %s did not match. Server: %s Client: %s%s className \"sc-gtLWhw hdQcJJ\" \"sc-egkSDF hqlzLC\" \n{\n goodMessages: 0,\n goodLabel: 'Clicked 1',\n goodStyleTags: 1,\n decoyMismatchWarnings: 1\n}\n{ fcpInlineMs: 26, fcpLinkedMs: 441, stylesheetDelayMs: 400 }\n{ rendersAdded: 0, hitsAdded: 10 }\nPASS\n\nReading run.mjs\n\nThe server picks a mode from the query string: ?mode=inline (default) puts the collected