@quicktvui/web-cli 3.1.0 → 3.1.2
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.
|
@@ -295,10 +295,17 @@
|
|
|
295
295
|
var sseTabId = 'qt-dev-tab-' + Date.now() + '-' + Math.random().toString(36).slice(2);
|
|
296
296
|
var sseLeaderKey = 'quicktvui-dev-sse-leader';
|
|
297
297
|
var sseLeaderTtl = 10000;
|
|
298
|
+
// 仅处理当前页面加载后发生的刷新事件,避免前后台切换时重放旧事件误刷新。
|
|
299
|
+
var pageLoadedAt = Date.now();
|
|
298
300
|
// 页面加载后的冷却期:这段时间内忽略 bundle-update 事件
|
|
299
301
|
// 防止 SSE 重连后收到缓存的旧 bundle-update 导致无限刷新
|
|
300
302
|
var sseCooldownUntil = Date.now() + 3000; // 3 秒冷却期
|
|
301
303
|
|
|
304
|
+
function isStaleReloadEvent(data) {
|
|
305
|
+
if (!data || typeof data.timestamp !== 'number') return false;
|
|
306
|
+
return data.timestamp <= pageLoadedAt;
|
|
307
|
+
}
|
|
308
|
+
|
|
302
309
|
function readSseLeader() {
|
|
303
310
|
try {
|
|
304
311
|
var raw = localStorage.getItem(sseLeaderKey);
|
|
@@ -392,6 +399,11 @@
|
|
|
392
399
|
if (data.type === 'connected') {
|
|
393
400
|
updateStatus('ready', '开发服务器已连接');
|
|
394
401
|
} else if (data.type === 'bundle-update') {
|
|
402
|
+
if (isStaleReloadEvent(data)) {
|
|
403
|
+
console.log('[Dev] Ignoring stale bundle-update', data.timestamp, '<=', pageLoadedAt);
|
|
404
|
+
updateStatus('ready', '构建完成');
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
395
407
|
if (Date.now() < sseCooldownUntil) {
|
|
396
408
|
console.log('[Dev] Ignoring bundle-update during cooldown');
|
|
397
409
|
updateStatus('ready', '构建完成');
|
|
@@ -400,6 +412,10 @@
|
|
|
400
412
|
updateStatus('building', 'Bundle 更新中...');
|
|
401
413
|
setTimeout(function() { location.reload(); }, 300);
|
|
402
414
|
} else if (data.type === 'full-reload') {
|
|
415
|
+
if (isStaleReloadEvent(data)) {
|
|
416
|
+
console.log('[Dev] Ignoring stale full-reload', data.timestamp, '<=', pageLoadedAt);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
403
419
|
if (Date.now() < sseCooldownUntil) {
|
|
404
420
|
console.log('[Dev] Ignoring full-reload during cooldown');
|
|
405
421
|
return;
|