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
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
import deepmerge from "deepmerge";
|
|
import { getRequestConfig } from "next-intl/server";
|
|
|
|
import type { TranslationObject } from ".";
|
|
import { fallbackLocale, isLocaleSupported } from ".";
|
|
import type { SupportedLanguage } from "./config";
|
|
import { createLanguageMapping } from "./mapping";
|
|
|
|
// ponytail: module-level memo — one merged object per locale used (~250-400 KB each).
|
|
// Ceiling: ~2 MB for 5 active locales. Upgrade: evict when size > 8.
|
|
const mergedMessages = new Map<SupportedLanguage, Promise<TranslationObject>>();
|
|
|
|
const loadMessagesAsync = (locale: SupportedLanguage): Promise<TranslationObject> => {
|
|
const existing = mergedMessages.get(locale);
|
|
if (existing) return existing;
|
|
|
|
const promise = (async () => {
|
|
const languageMap = createLanguageMapping();
|
|
const current = removeEmptyTranslations((await languageMap[locale]()).default) as TranslationObject;
|
|
if (locale === fallbackLocale) return current;
|
|
const fallback = (await languageMap[fallbackLocale]()).default;
|
|
return deepmerge(fallback, current) as TranslationObject;
|
|
})();
|
|
|
|
mergedMessages.set(locale, promise);
|
|
void promise.catch(() => {
|
|
if (mergedMessages.get(locale) === promise) mergedMessages.delete(locale);
|
|
});
|
|
return promise;
|
|
};
|
|
|
|
export default getRequestConfig(async ({ requestLocale }) => {
|
|
const requested = await requestLocale;
|
|
const locale: SupportedLanguage =
|
|
requested && isLocaleSupported(requested) ? (requested as SupportedLanguage) : fallbackLocale;
|
|
return { locale, messages: await loadMessagesAsync(locale) };
|
|
});
|
|
|
|
const removeEmptyTranslations = (translations: Record<string, unknown>): Record<string, unknown> => {
|
|
return Object.entries(translations).reduce(
|
|
(acc, [key, value]) => {
|
|
if (typeof value !== "string") {
|
|
return { ...acc, [key]: removeEmptyTranslations(value as Record<string, unknown>) };
|
|
}
|
|
if (value.trim() === "") {
|
|
return acc;
|
|
}
|
|
return { ...acc, [key]: value };
|
|
},
|
|
{} as Record<string, unknown>,
|
|
);
|
|
};
|