Preload terminal chart canvas
This commit is contained in:
@@ -63,9 +63,24 @@ const DEFERRED_DETAIL_LOAD_DELAY_MS = 1_200;
|
||||
const DEFERRED_DETAIL_LOAD_GROUP_SIZE = 3;
|
||||
const DEFERRED_DETAIL_LOAD_WAVE_STEP_MS = 900;
|
||||
|
||||
let temperatureChartCanvasModulePromise: Promise<
|
||||
typeof import("@/components/dashboard/scan-terminal/TemperatureChartCanvas")
|
||||
> | null = null;
|
||||
|
||||
function loadTemperatureChartCanvasModule() {
|
||||
temperatureChartCanvasModulePromise ??= import(
|
||||
"@/components/dashboard/scan-terminal/TemperatureChartCanvas"
|
||||
);
|
||||
return temperatureChartCanvasModulePromise;
|
||||
}
|
||||
|
||||
export function preloadTemperatureChartCanvas() {
|
||||
return loadTemperatureChartCanvasModule().then(() => undefined, () => undefined);
|
||||
}
|
||||
|
||||
const TemperatureChartCanvas = dynamic(
|
||||
() =>
|
||||
import("@/components/dashboard/scan-terminal/TemperatureChartCanvas").then(
|
||||
loadTemperatureChartCanvasModule().then(
|
||||
(mod) => mod.TemperatureChartCanvas,
|
||||
),
|
||||
{
|
||||
|
||||
@@ -72,6 +72,17 @@ export async function runTests() {
|
||||
chartSource.includes("2 * 60_000"),
|
||||
"selected city chart should consume SSE patches and use a 2-minute no-patch fallback",
|
||||
);
|
||||
assert(
|
||||
chartSource.includes("loadTemperatureChartCanvasModule") &&
|
||||
chartSource.includes("preloadTemperatureChartCanvas"),
|
||||
"terminal chart canvas should expose a preload hook for the dynamic chart chunk",
|
||||
);
|
||||
assert(
|
||||
dashboardSource.includes("preloadTemperatureChartCanvas") &&
|
||||
dashboardSource.includes("void preloadTemperatureChartCanvas()") &&
|
||||
dashboardSource.includes('activeNavKey !== "thresholds"'),
|
||||
"terminal screen should preload the chart chunk once access is confirmed on the chart tab",
|
||||
);
|
||||
assert(
|
||||
chartSource.includes("fetchHourlyForecastForCity(city, { ignoreCache: true, resolution: targetResolution })") &&
|
||||
chartSource.includes("setHourly(data)"),
|
||||
|
||||
Reference in New Issue
Block a user