perf: implement Phase 1 homepage diet via Next.js Cache Components

P1-0: V8 heap cap (HOMARR_MAX_OLD_SPACE_SIZE, default 512MB)
P1-1: Module graph cuts
  - Dynamic integration imports (55 static → lazy loaders)
  - Conditional DB driver loading (only configured driver loaded)
  - Replace jsdom with linkedom for SVG sanitization
  - Delete eager widget barrel (55 import * as → 0)
  - Extract createRetryableLoader to @homarr/common
P1-2: Enable cacheComponents + restructure root layout
  - Suspense boundaries around session-dependent providers
  - ColorSchemeScript replaces server-side cookie reads
  - Board/manage/auth layouts wrapped in Suspense
P1-3: Cache read paths
  - Cache tag registry + invalidation helpers
  - Cache invalidation wired into all mutation routers
  - Translation deep-merge memoized per locale
P1-4: Prerendered shells + loading.tsx files
P1-5: Shared integration data cache (60s TTL, stale-while-revalidate)
P1-6: Redis-backed Next.js cache handler (@homarr/next-cache-handler)
P1-7: Redis optional (memory channel fallback), TTL on pubSub:last:*,
      Redis clients consolidated from 6 to 2
This commit is contained in:
Thomas Camlong committed 2026-08-07 18:59:47 +02:00
1 parent 366ec6bdbc
commit 018f98e318
86 files changed
+2219 -1232

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ import type { SettingsContextProps } from "@homarr/settings/creator";
import type { stringOrTranslation } from "@homarr/translation";
import type { TablerIcon } from "@homarr/ui";
import type { WidgetImports } from ".";
import type { WidgetImports } from "./import";
import type { inferOptionsFromCreator, inferOptionsFromDefinition, WidgetOptionsRecord } from "./options";
export interface WidgetContextMenuAction {
+127 -1
View File
@@ -1,3 +1,129 @@
import type { WidgetKind } from "@homarr/definitions";
import type { IntegrationKind, WidgetKind } from "@homarr/definitions";
import type * as anchorNote from "./anchor-note";
import type * as app from "./app";
import type * as archiveTeamWarrior from "./archive-team-warrior";
import type * as audioStats from "./audio-stats";
import type * as bazarr from "./bazarr";
import type * as beszelAlerts from "./beszel-alerts";
import type * as beszelSystemGrid from "./beszel-system-grid";
import type * as beszelSystemStats from "./beszel-system-stats";
import type * as beszelSystemTable from "./beszel-system-table";
import type * as bookmarks from "./bookmarks";
import type * as calendar from "./calendar";
import type * as clock from "./clock";
import type * as coolify from "./coolify";
import type * as customApi from "./custom-api";
import type * as dnsHoleControls from "./dns-hole/controls";
import type * as dnsHoleSummary from "./dns-hole/summary";
import type * as dockerContainers from "./docker";
import type * as downloads from "./downloads";
import type * as firewall from "./firewall";
import type * as healthMonitoring from "./health-monitoring";
import type * as iframe from "./iframe";
import type * as immichAlbumCarousel from "./immich/album-carousel";
import type * as immichServerStats from "./immich/server-stats";
import type * as indexerManager from "./indexer-manager";
import type * as mediaMissing from "./media-missing";
import type * as mediaReleases from "./media-releases";
import type * as mediaRequestsList from "./media-requests/list";
import type * as mediaRequestsStats from "./media-requests/stats";
import type * as mediaServer from "./media-server";
import type * as mediaTranscoding from "./media-transcoding";
import type * as minecraftServerStatus from "./minecraft/server-status";
import type * as networkControllerStatus from "./network-controller/network-status";
import type * as networkControllerSummary from "./network-controller/summary";
import type * as notebook from "./notebook";
import type * as notifications from "./notifications";
import type * as paperlessNgx from "./paperless-ngx";
import type * as patchmon from "./patchmon";
import type * as releases from "./releases";
import type * as rssFeed from "./rssFeed";
import type * as smartHomeEntityState from "./smart-home/entity-state";
import type * as smartHomeExecuteAutomation from "./smart-home/execute-automation";
import type * as speedtestTracker from "./speedtest-tracker";
import type * as stockPrice from "./stocks";
import type * as systemDisks from "./system-disks";
import type * as systemResources from "./system-resources";
import type * as timetable from "./timetable";
import type * as tracearr from "./tracearr";
import type * as traefik from "./traefik";
import type * as umami from "./umami";
import type * as uptimeKuma from "./uptime-kuma";
import type * as ups from "./ups";
import type * as video from "./video";
import type * as vpn from "./vpn";
import type * as weather from "./weather";
export type WidgetImportRecord = Record<WidgetKind, unknown>;
export type WidgetImports = {
clock: typeof clock;
weather: typeof weather;
app: typeof app;
archiveTeamWarrior: typeof archiveTeamWarrior;
anchorNote: typeof anchorNote;
notebook: typeof notebook;
iframe: typeof iframe;
video: typeof video;
dnsHoleSummary: typeof dnsHoleSummary;
dnsHoleControls: typeof dnsHoleControls;
"smartHome-entityState": typeof smartHomeEntityState;
"smartHome-executeAutomation": typeof smartHomeExecuteAutomation;
stockPrice: typeof stockPrice;
mediaServer: typeof mediaServer;
calendar: typeof calendar;
downloads: typeof downloads;
"mediaRequests-requestList": typeof mediaRequestsList;
"mediaRequests-requestStats": typeof mediaRequestsStats;
mediaMissing: typeof mediaMissing;
networkControllerSummary: typeof networkControllerSummary;
networkControllerStatus: typeof networkControllerStatus;
rssFeed: typeof rssFeed;
bookmarks: typeof bookmarks;
bazarr: typeof bazarr;
indexerManager: typeof indexerManager;
healthMonitoring: typeof healthMonitoring;
mediaTranscoding: typeof mediaTranscoding;
minecraftServerStatus: typeof minecraftServerStatus;
dockerContainers: typeof dockerContainers;
releases: typeof releases;
firewall: typeof firewall;
notifications: typeof notifications;
mediaReleases: typeof mediaReleases;
systemResources: typeof systemResources;
coolify: typeof coolify;
systemDisks: typeof systemDisks;
timetable: typeof timetable;
"immich-serverStats": typeof immichServerStats;
"immich-albumCarousel": typeof immichAlbumCarousel;
paperlessNgx: typeof paperlessNgx;
patchmon: typeof patchmon;
tracearr: typeof tracearr;
speedtestTracker: typeof speedtestTracker;
uptimeKuma: typeof uptimeKuma;
audioStats: typeof audioStats;
umami: typeof umami;
vpn: typeof vpn;
ups: typeof ups;
beszelSystemTable: typeof beszelSystemTable;
beszelSystemGrid: typeof beszelSystemGrid;
beszelAlerts: typeof beszelAlerts;
beszelSystemStats: typeof beszelSystemStats;
traefik: typeof traefik;
customApi: typeof customApi;
};
export type WidgetImportKey = keyof WidgetImports;
export type inferSupportedIntegrations<TKind extends WidgetKind> = (WidgetImports[TKind]["definition"] extends {
supportedIntegrations: string[];
}
? WidgetImports[TKind]["definition"]["supportedIntegrations"]
: string[])[number];
export type inferSupportedIntegrationsStrict<TKind extends WidgetKind> = (WidgetImports[TKind]["definition"] extends {
supportedIntegrations: IntegrationKind[];
}
? WidgetImports[TKind]["definition"]["supportedIntegrations"]
: never[])[number];
-184
View File
@@ -1,184 +0,0 @@
import type { ComponentType } from "react";
import type { Loader } from "next/dynamic";
import dynamic from "next/dynamic";
import { Center, Loader as UiLoader } from "@mantine/core";
import { objectEntries } from "@homarr/common";
import type { IntegrationKind, WidgetKind } from "@homarr/definitions";
import type { SettingsContextProps } from "@homarr/settings/creator";
import * as anchorNote from "./anchor-note";
import * as audioStats from "./audio-stats";
import * as app from "./app";
import * as archiveTeamWarrior from "./archive-team-warrior";
import * as bookmarks from "./bookmarks";
import * as bazarr from "./bazarr";
import * as calendar from "./calendar";
import * as clock from "./clock";
import * as coolify from "./coolify";
import type { WidgetComponentProps } from "./definition";
import * as dnsHoleControls from "./dns-hole/controls";
import * as dnsHoleSummary from "./dns-hole/summary";
import * as dockerContainers from "./docker";
import * as downloads from "./downloads";
import * as firewall from "./firewall";
import * as healthMonitoring from "./health-monitoring";
import * as iframe from "./iframe";
import * as immichAlbumCarousel from "./immich/album-carousel";
import * as immichServerStats from "./immich/server-stats";
import type { WidgetImportRecord } from "./import";
import * as indexerManager from "./indexer-manager";
import * as mediaReleases from "./media-releases";
import * as mediaRequestsList from "./media-requests/list";
import * as mediaRequestsStats from "./media-requests/stats";
import * as mediaServer from "./media-server";
import * as mediaTranscoding from "./media-transcoding";
import * as mediaMissing from "./media-missing";
import * as minecraftServerStatus from "./minecraft/server-status";
import * as networkControllerStatus from "./network-controller/network-status";
import * as networkControllerSummary from "./network-controller/summary";
import * as notebook from "./notebook";
import * as paperlessNgx from "./paperless-ngx";
import * as patchmon from "./patchmon";
import * as notifications from "./notifications";
import type { WidgetOptionDefinition } from "./options";
import * as releases from "./releases";
import * as rssFeed from "./rssFeed";
import * as smartHomeEntityState from "./smart-home/entity-state";
import * as smartHomeExecuteAutomation from "./smart-home/execute-automation";
import * as speedtestTracker from "./speedtest-tracker";
import * as uptimeKuma from "./uptime-kuma";
import * as stockPrice from "./stocks";
import * as systemDisks from "./system-disks";
import * as systemResources from "./system-resources";
import * as timetable from "./timetable";
import * as traefik from "./traefik";
import * as tracearr from "./tracearr";
import * as umami from "./umami";
import * as ups from "./ups";
import * as vpn from "./vpn";
import * as beszelSystemTable from "./beszel-system-table";
import * as beszelSystemGrid from "./beszel-system-grid";
import * as beszelAlerts from "./beszel-alerts";
import * as beszelSystemStats from "./beszel-system-stats";
import * as video from "./video";
import * as weather from "./weather";
import * as customApi from "./custom-api";
export type {
WidgetDefinition,
WidgetContextMenuAction,
WidgetContextActionProps,
WidgetOptionsSettings,
} from "./definition";
export type { WidgetComponentProps };
export type { WidgetOptionDefinition, WidgetOptionType } from "./options";
export const widgetImports = {
clock,
weather,
app,
archiveTeamWarrior,
anchorNote,
notebook,
iframe,
video,
dnsHoleSummary,
dnsHoleControls,
"smartHome-entityState": smartHomeEntityState,
"smartHome-executeAutomation": smartHomeExecuteAutomation,
stockPrice,
mediaServer,
calendar,
downloads,
"mediaRequests-requestList": mediaRequestsList,
"mediaRequests-requestStats": mediaRequestsStats,
mediaMissing,
networkControllerSummary,
networkControllerStatus,
rssFeed,
bookmarks,
bazarr,
indexerManager,
healthMonitoring,
mediaTranscoding,
minecraftServerStatus,
dockerContainers,
releases,
firewall,
notifications,
mediaReleases,
systemResources,
coolify,
systemDisks,
timetable,
"immich-serverStats": immichServerStats,
"immich-albumCarousel": immichAlbumCarousel,
paperlessNgx,
patchmon,
tracearr,
speedtestTracker,
uptimeKuma,
audioStats,
umami,
vpn,
ups,
beszelSystemTable,
beszelSystemGrid,
beszelAlerts,
beszelSystemStats,
traefik,
customApi,
} satisfies WidgetImportRecord;
export type WidgetImports = typeof widgetImports;
export type WidgetImportKey = keyof WidgetImports;
const loadedComponents = new Map<WidgetKind, ComponentType<WidgetComponentProps<WidgetKind>>>();
export const loadWidgetDynamic = <TKind extends WidgetKind>(kind: TKind) => {
const existingComponent = loadedComponents.get(kind);
if (existingComponent) return existingComponent;
const newlyLoadedComponent = dynamic<WidgetComponentProps<TKind>>(
widgetImports[kind].componentLoader as Loader<WidgetComponentProps<TKind>>,
{
loading: () => (
<Center w="100%" h="100%">
<UiLoader />
</Center>
),
},
);
loadedComponents.set(kind, newlyLoadedComponent as never);
return newlyLoadedComponent;
};
export type inferSupportedIntegrations<TKind extends WidgetKind> = (WidgetImports[TKind]["definition"] extends {
supportedIntegrations: string[];
}
? WidgetImports[TKind]["definition"]["supportedIntegrations"]
: string[])[number];
export type inferSupportedIntegrationsStrict<TKind extends WidgetKind> = (WidgetImports[TKind]["definition"] extends {
supportedIntegrations: IntegrationKind[];
}
? WidgetImports[TKind]["definition"]["supportedIntegrations"]
: never[])[number];
export const reduceWidgetOptionsWithDefaultValues = (
kind: WidgetKind,
settings: Pick<SettingsContextProps, "enableStatusByDefault" | "forceDisableStatus">,
currentValue: Record<string, unknown> = {},
) => {
const definition = widgetImports[kind].definition;
const options = definition.createOptions(settings) as Record<string, WidgetOptionDefinition>;
return objectEntries(options).reduce(
(prev, [key, value]) => ({
...prev,
[key]: currentValue[key] ?? value.defaultValue,
}),
{} as Record<string, unknown>,
);
};
+1 -1
View File
@@ -1,10 +1,10 @@
import type { QueryKey } from "@tanstack/react-query";
import { describe, expect, it } from "vitest";
import { createRetryableLoader } from "@homarr/common";
import { widgetIntegrationSupport, widgetKinds as definedWidgetKinds } from "@homarr/definitions";
import {
createRetryableLoader,
loadAllWidgetDefinitions,
loadWidgetComponent,
loadWidgetDefinition,
+1 -20
View File
@@ -1,6 +1,6 @@
import type { ComponentType } from "react";
import { objectEntries } from "@homarr/common";
import { createRetryableLoader, objectEntries } from "@homarr/common";
import type { WidgetKind } from "@homarr/definitions";
import type { SettingsContextProps } from "@homarr/settings/creator";
@@ -143,25 +143,6 @@ const definitionPromises = new Map<WidgetKind, Promise<WidgetDefinition>>();
export const widgetKinds = Object.keys(moduleLoaders) as WidgetKind[];
export const createRetryableLoader = <TKey, TValue>(loaders: ReadonlyMap<TKey, () => Promise<TValue>>) => {
const promises = new Map<TKey, Promise<TValue>>();
return (key: TKey) => {
const existing = promises.get(key);
if (existing) return existing;
const loader = loaders.get(key);
if (!loader) throw new Error(`No loader is registered for ${String(key)}`);
const promise = loader();
promises.set(key, promise);
void promise.catch(() => {
if (promises.get(key) === promise) promises.delete(key);
});
return promise;
};
};
export const loadWidgetModule = createRetryableLoader(
new Map(Object.entries(moduleLoaders) as [WidgetKind, () => Promise<WidgetModule>][]),
);