@quicktvui/web-cli 2.1.0 → 2.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.
package/bin/qt-web-cli.js CHANGED
@@ -194,6 +194,8 @@ async function main() {
194
194
  },
195
195
  onReady: () => {
196
196
  // 构建完成后,通知浏览器
197
+ // notifyBuildStatus 会更新 lastEvent 为 build-status:ready
198
+ // 这样 SSE 重连后收到的是 ready 而不是旧的 bundle-update
197
199
  hotReloader.notifyBuildStatus('ready', '构建完成')
198
200
 
199
201
  // 更新 bundle URL
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-cli",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "CLI tool for QuickTVUI web development v2 - delegate build & bundle loading",
5
5
  "author": "QuickTVUI Team",
6
6
  "license": "Apache-2.0",
@@ -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') {