2
0
Просмотр исходного кода

⚡️ perf(progress): optimize loading completion detection logic

- 调整客户端模式完成阈值从85%降低到80%,提高完成检测灵敏度
- 添加95%和97%资源完成的阶梯式检测条件,缩短不同完成阶段的等待时间
- 服务端模式超时时间从2000ms减少到1500ms,加快整体完成速度
- 全局超时时间从3000ms减少到2000ms,避免过长等待

📝 docs(debug): add detailed completion debugging logs

- 添加完整的checkCompletion调试日志输出,包含各阶段状态和阈值检查结果
- 使用✅、❌、⏰、⏳等符号增强日志可读性,明确显示不同检查结果
- 添加资源完成百分比、超时剩余时间等关键调试信息
- 增加调试日志分隔符,提升日志结构清晰度
yourname 7 месяцев назад
Родитель
Сommit
0403ae5b2e
1 измененных файлов с 44 добавлено и 14 удалено
  1. 44 14
      vite-plugin-compile-progress.js

+ 44 - 14
vite-plugin-compile-progress.js

@@ -134,41 +134,71 @@ export function progressTrackingPlugin() {
                     }, 2000);  
                   }  
   
-                  // 检测是否完成加载  
+                  // 在 checkCompletion 函数中进一步优化完成条件  
                   function checkCompletion() {  
                     const now = Date.now();  
                     const timeSinceLastResource = now - lastResourceTime;  
                       
+                    // 添加详细的调试日志  
+                    console.log('=== checkCompletion Debug ===');  
+                    console.log('hasServerActivity:', hasServerActivity);  
+                    console.log('serverProgress:', serverProgress);  
+                    console.log('resourcesCompleted:', resourcesCompleted);  
+                    console.log('estimatedTotal:', estimatedTotal);  
+                    console.log('timeSinceLastResource:', timeSinceLastResource);  
+                    console.log('isLoading:', isLoading);  
+                      
                     // 根据服务端活动情况调整完成条件  
                     if (!hasServerActivity) {  
-                      // 无服务端编译时,主要依赖客户端资源  
-                      if (resourcesCompleted >= estimatedTotal * 0.85 && timeSinceLastResource > 1500) {  
-                        console.log('Client-only loading complete (85% threshold)');  
+                      console.log('Checking client-only completion conditions...');  
+                        
+                      // 客户端模式下的完成条件更加宽松  
+                      if (resourcesCompleted >= estimatedTotal * 0.8 && timeSinceLastResource > 1000) {  
+                        console.log('✅ Client-only loading complete (80% threshold)');  
+                        forceComplete();  
+                        return;  
+                      }  
+                        
+                      // 如果进度超过95%且1秒无新资源,立即完成  
+                      if (resourcesCompleted >= estimatedTotal * 0.95 && timeSinceLastResource > 1000) {  
+                        console.log('✅ Client-only loading complete (95% threshold)');  
                         forceComplete();  
                         return;  
                       }  
                         
-                      // 如果进度超过90%且1.5秒无新资源,强制完成  
-                      if (resourcesCompleted >= estimatedTotal * 0.9 && timeSinceLastResource > 1500) {  
-                        console.log('Client-only loading complete (90% threshold)');  
+                      // 如果进度超过97%且0.5秒无新资源,立即完成  
+                      if (resourcesCompleted >= estimatedTotal * 0.97 && timeSinceLastResource > 500) {  
+                        console.log('✅ Client-only loading complete (97% threshold)');  
                         forceComplete();  
                         return;  
                       }  
+                        
+                      console.log('❌ Client-only conditions not met');  
                     } else {  
-                      // 有服务端编译时,需要服务端完成  
-                      if (serverProgress >= 1.0 && timeSinceLastResource > 2000) {  
-                        console.log('Server + client loading complete');  
+                      console.log('Checking mixed mode completion conditions...');  
+                        
+                      // 有服务端编译时的完成条件  
+                      if (serverProgress >= 1.0 && timeSinceLastResource > 1500) {  
+                        console.log('✅ Server + client loading complete');  
                         forceComplete();  
                         return;  
                       }  
+                        
+                      console.log('❌ Mixed mode conditions not met');  
+                      console.log('serverProgress >= 1.0:', serverProgress >= 1.0);  
+                      console.log('timeSinceLastResource > 1500:', timeSinceLastResource > 1500);  
                     }  
                       
-                    // 超时强制完成 - 缩短超时时间  
-                    if (timeSinceLastResource > 3000) {  
-                      console.log('Force completing due to timeout (3s)');  
+                    // 超时强制完成 - 进一步缩短超时时间  
+                    if (timeSinceLastResource > 2000) {  
+                      console.log('⏰ Force completing due to timeout (2s)');  
                       forceComplete();  
+                    } else {  
+                      console.log('⏳ Waiting for timeout, remaining:', 2000 - timeSinceLastResource, 'ms');  
                     }  
-                  }  
+                      
+                    console.log('=== End checkCompletion Debug ===');  
+                  }
   
                   // 强制完成  
                   function forceComplete() {