|
|
@@ -114,7 +114,7 @@ export function progressTrackingPlugin() {
|
|
|
const preloadLinks = document.querySelectorAll('link[rel="preload"], link[rel="modulepreload"]').length;
|
|
|
|
|
|
const baseEstimate = scripts + links + styleSheets + preloadLinks;
|
|
|
- const conservativeEstimate = Math.max(baseEstimate + 10, 15);
|
|
|
+ const conservativeEstimate = Math.max(baseEstimate + 8, 12);
|
|
|
|
|
|
return conservativeEstimate;
|
|
|
}
|
|
|
@@ -124,13 +124,14 @@ export function progressTrackingPlugin() {
|
|
|
hasServerActivity = true;
|
|
|
if (serverActivityTimer) clearTimeout(serverActivityTimer);
|
|
|
|
|
|
- // 如果3秒内没有新的服务端活动,认为服务端编译已完成或无需编译
|
|
|
+ // 如果2秒内没有新的服务端活动,认为服务端编译已完成或无需编译
|
|
|
serverActivityTimer = setTimeout(() => {
|
|
|
if (serverProgress === 0) {
|
|
|
console.log('No server compilation detected - using client-only mode');
|
|
|
hasServerActivity = false;
|
|
|
+ updateProgress();
|
|
|
}
|
|
|
- }, 3000);
|
|
|
+ }, 2000);
|
|
|
}
|
|
|
|
|
|
// 检测是否完成加载
|
|
|
@@ -141,8 +142,15 @@ export function progressTrackingPlugin() {
|
|
|
// 根据服务端活动情况调整完成条件
|
|
|
if (!hasServerActivity) {
|
|
|
// 无服务端编译时,主要依赖客户端资源
|
|
|
- if (resourcesCompleted >= estimatedTotal * 0.8 && timeSinceLastResource > 2000) {
|
|
|
- console.log('Client-only loading complete');
|
|
|
+ if (resourcesCompleted >= estimatedTotal * 0.85 && timeSinceLastResource > 1500) {
|
|
|
+ console.log('Client-only loading complete (85% threshold)');
|
|
|
+ forceComplete();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果进度超过90%且1.5秒无新资源,强制完成
|
|
|
+ if (resourcesCompleted >= estimatedTotal * 0.9 && timeSinceLastResource > 1500) {
|
|
|
+ console.log('Client-only loading complete (90% threshold)');
|
|
|
forceComplete();
|
|
|
return;
|
|
|
}
|
|
|
@@ -155,9 +163,9 @@ export function progressTrackingPlugin() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 超时强制完成
|
|
|
- if (timeSinceLastResource > 5000) {
|
|
|
- console.log('Force completing due to timeout');
|
|
|
+ // 超时强制完成 - 缩短超时时间
|
|
|
+ if (timeSinceLastResource > 3000) {
|
|
|
+ console.log('Force completing due to timeout (3s)');
|
|
|
forceComplete();
|
|
|
}
|
|
|
}
|
|
|
@@ -221,9 +229,9 @@ export function progressTrackingPlugin() {
|
|
|
console.log(\`Progress: Total \${Math.round(totalProgress)}%\`);
|
|
|
|
|
|
// 如果接近完成,开始检测完成状态
|
|
|
- if (totalProgress >= 90) {
|
|
|
+ if (totalProgress >= 85) {
|
|
|
if (completionTimer) clearTimeout(completionTimer);
|
|
|
- completionTimer = setTimeout(checkCompletion, 1000);
|
|
|
+ completionTimer = setTimeout(checkCompletion, 800);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -254,9 +262,9 @@ export function progressTrackingPlugin() {
|
|
|
resourcesCompleted++;
|
|
|
lastResourceTime = Date.now();
|
|
|
|
|
|
- // 动态调整预估总数
|
|
|
- if (resourcesCompleted > estimatedTotal * 0.9) {
|
|
|
- estimatedTotal = Math.max(estimatedTotal, resourcesCompleted + 3);
|
|
|
+ // 更保守的总数调整策略
|
|
|
+ if (resourcesCompleted > estimatedTotal * 0.95) {
|
|
|
+ estimatedTotal = Math.max(estimatedTotal, resourcesCompleted + 1);
|
|
|
}
|
|
|
|
|
|
console.log(\`Resource completed: \${entry.name} (type: \${entry.initiatorType})\`);
|
|
|
@@ -296,14 +304,19 @@ export function progressTrackingPlugin() {
|
|
|
function handlePageLoad() {
|
|
|
setTimeout(() => {
|
|
|
if (resourcesCompleted > 0) {
|
|
|
- estimatedTotal = Math.max(resourcesCompleted + 2, estimatedTotal);
|
|
|
+ estimatedTotal = Math.max(resourcesCompleted + 1, estimatedTotal);
|
|
|
console.log(\`Final estimated total: \${estimatedTotal}\`);
|
|
|
}
|
|
|
updateProgress();
|
|
|
|
|
|
- // 开始完成检测
|
|
|
- setTimeout(checkCompletion, 2000);
|
|
|
- }, 1000);
|
|
|
+ // 页面加载完成后,更积极地检测完成状态
|
|
|
+ setTimeout(() => {
|
|
|
+ if (isLoading && resourcesCompleted >= estimatedTotal * 0.8) {
|
|
|
+ console.log('Page load complete, forcing finish');
|
|
|
+ forceComplete();
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
+ }, 500);
|
|
|
}
|
|
|
|
|
|
// 根据文档状态初始化
|