perf: optimize dashboard loading and builds
This commit is contained in:
135 files changed
+8521
-1718
No files matched your search
@@ -8,13 +8,43 @@ import { supportedLanguages } from "@homarr/translation/languages";
|
||||
import { createI18nMiddleware } from "@homarr/translation/middleware";
|
||||
|
||||
let isOnboardingFinished = false;
|
||||
let onboardingStepPromise: Promise<string> | null = null;
|
||||
let defaultLocalePromise: Promise<string> | null = null;
|
||||
|
||||
const getOnboardingStepDedupedAsync = () => {
|
||||
onboardingStepPromise ??= getOnboardingStepForProxyAsync().then(
|
||||
(step) => {
|
||||
onboardingStepPromise = null;
|
||||
return step;
|
||||
},
|
||||
(error: unknown) => {
|
||||
onboardingStepPromise = null;
|
||||
throw error;
|
||||
},
|
||||
);
|
||||
return onboardingStepPromise;
|
||||
};
|
||||
|
||||
const getDefaultLocaleDedupedAsync = () => {
|
||||
defaultLocalePromise ??= getDefaultLocaleForProxyAsync().then(
|
||||
(locale) => {
|
||||
defaultLocalePromise = null;
|
||||
return locale;
|
||||
},
|
||||
(error: unknown) => {
|
||||
defaultLocalePromise = null;
|
||||
throw error;
|
||||
},
|
||||
);
|
||||
return defaultLocalePromise;
|
||||
};
|
||||
|
||||
export async function proxy(request: NextRequest) {
|
||||
// Redirect to onboarding if it's not finished yet
|
||||
const pathname = request.nextUrl.pathname;
|
||||
|
||||
if (!isOnboardingFinished && !pathname.endsWith("/init")) {
|
||||
const currentOnboardingStep = await getOnboardingStepForProxyAsync();
|
||||
const currentOnboardingStep = await getOnboardingStepDedupedAsync();
|
||||
if (currentOnboardingStep !== "finish") {
|
||||
return NextResponse.redirect(new URL("/init", request.url));
|
||||
}
|
||||
@@ -26,7 +56,7 @@ export async function proxy(request: NextRequest) {
|
||||
const currentLocale = request.cookies.get(localeCookieKey)?.value;
|
||||
let defaultLocale: SupportedLanguage = "en";
|
||||
if (!currentLocale || !supportedLanguages.includes(currentLocale as SupportedLanguage)) {
|
||||
const configuredLocale = await getDefaultLocaleForProxyAsync();
|
||||
const configuredLocale = await getDefaultLocaleDedupedAsync();
|
||||
if (supportedLanguages.includes(configuredLocale as SupportedLanguage)) {
|
||||
defaultLocale = configuredLocale as SupportedLanguage;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user