From adfa0ca34c4b36db958f8ba55f1942dff3859ca3 Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Fri, 10 Jul 2026 20:18:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(design):=20=E5=8E=9F=E5=9E=8B=20serve=20?= =?UTF-8?q?=E7=83=AD=E9=87=8D=E8=BD=BD=20SSE=20=E6=94=B9=E7=9F=AD=E8=BD=AE?= =?UTF-8?q?=E8=AF=A2=E2=80=94=E2=80=94=E5=A4=9A=E6=A0=87=E7=AD=BE=20SSE=20?= =?UTF-8?q?=E5=B8=B8=E9=A9=BB=E8=BF=9E=E6=8E=A5=E5=8D=A0=E6=BB=A1=20Chrome?= =?UTF-8?q?=20=E5=90=8C=E5=9F=9F=206=20=E8=BF=9E=E6=8E=A5=E4=B8=8A?= =?UTF-8?q?=E9=99=90=E8=87=B4=E6=95=B4=E7=AB=99=E5=8D=A1=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- design/prototype/serve.mjs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) 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); });