@quicktvui/web-cli 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/qt-web-cli.js +4 -0
- package/lib/HotReloader.js +12 -0
- package/package.json +1 -1
- package/templates/dev-renderer.html +13 -0
package/bin/qt-web-cli.js
CHANGED
|
@@ -209,6 +209,10 @@ async function main() {
|
|
|
209
209
|
const url = `http://localhost:${args.port}?bundle=${urlPath}`
|
|
210
210
|
openBrowser(url)
|
|
211
211
|
}
|
|
212
|
+
|
|
213
|
+
// 清除 HotReloader 中缓存的 bundle-update 事件
|
|
214
|
+
// 防止 SSE 重连后再次触发页面刷新导致无限循环
|
|
215
|
+
hotReloader.clearLastEvent()
|
|
212
216
|
},
|
|
213
217
|
})
|
|
214
218
|
|
package/lib/HotReloader.js
CHANGED
|
@@ -93,9 +93,21 @@ class HotReloader {
|
|
|
93
93
|
timestamp: Date.now(),
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
this.lastEventType = 'build-status'
|
|
97
|
+
this.lastEventData = { status, message }
|
|
98
|
+
|
|
96
99
|
this._broadcast(event)
|
|
97
100
|
}
|
|
98
101
|
|
|
102
|
+
/**
|
|
103
|
+
* 清除缓存的最后事件
|
|
104
|
+
* 防止 SSE 重连后再次发送旧的 bundle-update 导致无限刷新
|
|
105
|
+
*/
|
|
106
|
+
clearLastEvent() {
|
|
107
|
+
this.lastEventType = null
|
|
108
|
+
this.lastEventData = null
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
/**
|
|
100
112
|
* 广播事件到所有客户端
|
|
101
113
|
*/
|
package/package.json
CHANGED
|
@@ -289,6 +289,9 @@
|
|
|
289
289
|
|
|
290
290
|
// ========== SSE 热更新 ==========
|
|
291
291
|
var sseConnected = false;
|
|
292
|
+
// 页面加载后的冷却期:这段时间内忽略 bundle-update 事件
|
|
293
|
+
// 防止 SSE 重连后收到缓存的旧 bundle-update 导致无限刷新
|
|
294
|
+
var sseCooldownUntil = Date.now() + 3000; // 3 秒冷却期
|
|
292
295
|
if (window.__BUNDLE_CONFIG__ && window.__BUNDLE_CONFIG__.watch) {
|
|
293
296
|
try {
|
|
294
297
|
var sse = new EventSource(window.__BUNDLE_CONFIG__.sseEndpoint);
|
|
@@ -304,9 +307,19 @@
|
|
|
304
307
|
if (data.type === 'connected') {
|
|
305
308
|
updateStatus('ready', '开发服务器已连接');
|
|
306
309
|
} else if (data.type === 'bundle-update') {
|
|
310
|
+
// 冷却期内忽略 bundle-update(可能是 SSE 重连后缓存的旧事件)
|
|
311
|
+
if (Date.now() < sseCooldownUntil) {
|
|
312
|
+
console.log('[Dev] Ignoring bundle-update during cooldown');
|
|
313
|
+
updateStatus('ready', '已连接 - 等待变化');
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
307
316
|
updateStatus('building', 'Bundle 更新中...');
|
|
308
317
|
setTimeout(function() { location.reload(); }, 300);
|
|
309
318
|
} else if (data.type === 'full-reload') {
|
|
319
|
+
if (Date.now() < sseCooldownUntil) {
|
|
320
|
+
console.log('[Dev] Ignoring full-reload during cooldown');
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
310
323
|
updateStatus('building', '正在刷新...');
|
|
311
324
|
setTimeout(function() { location.reload(); }, 300);
|
|
312
325
|
} else if (data.type === 'build-status') {
|