diff --git a/design/prototype/serve.mjs b/design/prototype/serve.mjs index de7d6c2..7e56bca 100644 --- a/design/prototype/serve.mjs +++ b/design/prototype/serve.mjs @@ -20,24 +20,26 @@ const MIME = { '.woff2': 'font/woff2', }; -const clients = new Set(); +// 热重载改短轮询(2026-07-10):原 SSE 每个 tab 一条常驻连接,Chrome 同域 +// HTTP/1.1 上限 6 条——开到第 7 个原型 tab 连接池耗尽整站卡死。轮询即用即断,无上限。 +let version = 0; const RELOAD_SNIPPET = `\n\n`; const server = http.createServer((req, res) => { - if (req.url === '/__reload') { - res.writeHead(200, { - 'Content-Type': 'text/event-stream', - 'Cache-Control': 'no-cache', - Connection: 'keep-alive', - }); - res.write('retry: 500\n\n'); - clients.add(res); - req.on('close', () => clients.delete(res)); + if (req.url === '/__version' || req.url === '/__reload') { + res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }); + res.end(JSON.stringify({ v: version })); return; } @@ -85,7 +87,7 @@ fs.watch(ROOT, { recursive: true }, (_ev, file) => { if (file && file.endsWith('serve.mjs')) return; clearTimeout(debounce); debounce = setTimeout(() => { - for (const c of clients) c.write('data: reload\n\n'); + version++; if (file && /\.(html|css|js)$/.test(file)) runDsCheck(); }, 80); });