Remove dashboard prewarm requests

This commit is contained in:
2569718930@qq.com
2026-04-15 15:51:08 +08:00
parent aa6ed30987
commit c55b83a134
3 changed files with 7 additions and 214 deletions
+1 -13
View File
@@ -5,7 +5,7 @@ import clsx from "clsx";
import { useRouter } from "next/navigation";
import { useEffect, useMemo, useRef, useState } from "react";
import { ForecastTable } from "@/components/dashboard/PanelSections";
import { preloadChartJs, useChart } from "@/hooks/useChart";
import { useChart } from "@/hooks/useChart";
import { useDashboardStore } from "@/hooks/useDashboardStore";
import { useI18n } from "@/hooks/useI18n";
import { getOfficialSourceLinks } from "@/lib/dashboard-official-sources";
@@ -360,12 +360,6 @@ export function DetailPanel() {
: `${t("detail.todayAnalysis")} (Pro)`
}
onClick={() => handleFeatureAccess("today")}
onFocus={() => {
void preloadChartJs();
}}
onMouseEnter={() => {
void preloadChartJs();
}}
disabled={!store.selectedCity}
>
{isPro
@@ -379,12 +373,6 @@ export function DetailPanel() {
isPro ? t("detail.history") : `${t("detail.history")} (Pro)`
}
onClick={() => handleFeatureAccess("history")}
onFocus={() => {
void preloadChartJs();
}}
onMouseEnter={() => {
void preloadChartJs();
}}
disabled={!store.selectedCity}
>
{isPro ? t("detail.history") : `${t("detail.history")} · Pro`}
@@ -6,7 +6,6 @@ import {
DashboardStoreProvider,
useDashboardStore,
} from "@/hooks/useDashboardStore";
import { preloadChartJs } from "@/hooks/useChart";
import { I18nProvider, useI18n } from "@/hooks/useI18n";
import { CitySidebar } from "@/components/dashboard/CitySidebar";
import { DetailPanel } from "@/components/dashboard/DetailPanel";
@@ -82,42 +81,6 @@ function DashboardScreen() {
};
}, [store]);
useEffect(() => {
const browserWindow = window as Window & {
requestIdleCallback?: (
cb: IdleRequestCallback,
options?: IdleRequestOptions,
) => number;
cancelIdleCallback?: (handle: number) => void;
};
if (typeof browserWindow.requestIdleCallback === "function") {
const handle = browserWindow.requestIdleCallback(() => {
void loadHistoryModal();
void loadFutureForecastModal();
}, { timeout: 1200 });
return () => {
if (typeof browserWindow.cancelIdleCallback === "function") {
browserWindow.cancelIdleCallback(handle);
}
};
}
const timeoutId = window.setTimeout(() => {
void loadHistoryModal();
void loadFutureForecastModal();
}, 500);
return () => {
window.clearTimeout(timeoutId);
};
}, []);
useEffect(() => {
if (!store.selectedCity) return;
void preloadChartJs();
void loadHistoryModal();
void loadFutureForecastModal();
}, [store.selectedCity]);
// Avoid full-page flashing on initial load; only show this overlay for manual refresh.
const showLoading =
store.loadingState.cities ||