diff --git a/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts b/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts index 8bfe5ba4..02649779 100644 --- a/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts +++ b/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts @@ -106,7 +106,10 @@ export function generateKeycloakThemeResources( fs.writeFileSync( pathJoin(themeDirPath, "theme.properties"), - Buffer.from(`import=common/${themeName}\n`, "utf8") + Buffer.from([ + `[import=common/${themeName}`, + "locales=ca,cs,de,en,es,fr,it,ja,lt,nl,no,pl,pt-BR,ru,sk,sv,tr,zh-CN" + ].join("\n"), "utf8") ); } diff --git a/src/lib/components/Template.tsx b/src/lib/components/Template.tsx index c87efb24..d031989d 100644 --- a/src/lib/components/Template.tsx +++ b/src/lib/components/Template.tsx @@ -1,5 +1,5 @@ -import { useState, useEffect, memo } from "react"; +import { useState, useReducer ,useEffect, memo } from "react"; import type { ReactNode } from "react"; import { useKcTranslation } from "../i18n/useKcTranslation"; import { kcContext } from "../kcContext"; @@ -9,8 +9,7 @@ import { useKcLanguageTag } from "../i18n/useKcLanguageTag"; import type { KcLanguageTag } from "../i18n/KcLanguageTag"; import { getKcLanguageTagLabel } from "../i18n/KcLanguageTag"; import { useCallbackFactory } from "powerhooks"; -import { appendLinkInHead } from "../tools/appendLinkInHead"; -import { appendScriptInHead } from "../tools/appendScriptInHead"; +import { appendHead } from "../tools/appendHead"; import { join as pathJoin } from "path"; import { useConstCallback } from "powerhooks"; import type { KcTemplateProperties } from "./KcProperties"; @@ -69,36 +68,48 @@ export const Template = memo((props: TemplateProps) => { kcContext )); + const [isExtraCssLoaded, setExtraCssLoaded] = useReducer(() => true, false); + useEffect(() => { - kcProperties.stylesCommon?.forEach( - relativePath => - appendLinkInHead( - { "href": pathJoin(url.resourcesCommonPath, relativePath) } - ) - ); + let isUnmounted = false; - kcProperties.styles?.forEach( - relativePath => - appendLinkInHead( - { "href": pathJoin(url.resourcesPath, relativePath) } - ) - ); + Promise.all( + [ + ...(kcProperties.stylesCommon ?? []).map(relativePath => pathJoin(url.resourcesCommonPath, relativePath)), + ...(kcProperties.styles ?? []).map(relativePath => pathJoin(url.resourcesPath, relativePath)) + ].map(href => appendHead({ + "type": "css", + href + }))).then(() => { + + if (isUnmounted) { + return; + } + + setExtraCssLoaded(); + + }); kcProperties.scripts?.forEach( - relativePath => - appendScriptInHead( - { "src": pathJoin(url.resourcesPath, relativePath) } - ) + relativePath => appendHead({ + "type": "javascript", + "src": pathJoin(url.resourcesPath, relativePath) + }) ); document.getElementsByTagName("html")[0] .classList .add(cx(kcProperties.kcHtmlClass)); + return () => { isUnmounted = true; }; }, []); + if (!isExtraCssLoaded) { + return null; + } + return (