From fe31c8e08d2adef681f45b10f8e46cef9764e6b3 Mon Sep 17 00:00:00 2001 From: andrey-canon Date: Tue, 16 Jan 2024 12:24:38 -0500 Subject: [PATCH] feat: this changes the priority of theme overrides --- .../hooks/paragon/useParagonThemeCore.js | 2 +- .../hooks/paragon/useParagonThemeVariants.js | 27 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/react/hooks/paragon/useParagonThemeCore.js b/src/react/hooks/paragon/useParagonThemeCore.js index d3b5983bb..fd9b75514 100644 --- a/src/react/hooks/paragon/useParagonThemeCore.js +++ b/src/react/hooks/paragon/useParagonThemeCore.js @@ -106,7 +106,7 @@ const useParagonThemeCore = ({ const paragonCoreThemeLink = createCoreThemeLink(themeCore.urls.default); document.head.insertAdjacentElement( - 'afterbegin', + 'beforeend', paragonCoreThemeLink, ); diff --git a/src/react/hooks/paragon/useParagonThemeVariants.js b/src/react/hooks/paragon/useParagonThemeVariants.js index 737129ef9..809ca9006 100644 --- a/src/react/hooks/paragon/useParagonThemeVariants.js +++ b/src/react/hooks/paragon/useParagonThemeVariants.js @@ -77,6 +77,8 @@ const useParagonThemeVariants = ({ setIsBrandThemeVariantLoaded(true); return; } + const getParagonThemeCoreLink = () => document.head.querySelector('link[data-paragon-theme-core="true"]'); + const getBrandThemeCoreLink = () => document.head.querySelector('link[data-brand-theme-core="true"]'); const getParagonThemeVariantLink = () => document.head.querySelector(`link[data-paragon-theme-variant='${themeVariant}']`); const existingThemeVariantLink = document.head.querySelector(`link[href='${value.urls.default}']`); const existingThemeVariantBrandLink = document.head.querySelector(`link[href='${value.urls.brandOverride}']`); @@ -162,10 +164,25 @@ const useParagonThemeVariants = ({ if (!existingThemeVariantLink) { const paragonThemeVariantLink = createThemeVariantLink(value.urls.default); - document.head.insertAdjacentElement( - 'afterbegin', - paragonThemeVariantLink, - ); + const foundParagonThemeCoreLink = getParagonThemeCoreLink(); + const foundBrandThemeCoreLink = getBrandThemeCoreLink(); + + if (foundBrandThemeCoreLink) { + foundBrandThemeCoreLink.insertAdjacentElement( + 'afterend', + paragonThemeVariantLink, + ); + } else if (foundParagonThemeCoreLink) { + foundParagonThemeCoreLink.insertAdjacentElement( + 'afterend', + paragonThemeVariantLink, + ); + } else { + document.head.insertAdjacentElement( + 'beforeend', + paragonThemeVariantLink, + ); + } if (value.urls.brandOverride) { const brandThemeVariantLink = createThemeVariantLink(value.urls.brandOverride, { isBrandOverride: true }); @@ -177,7 +194,7 @@ const useParagonThemeVariants = ({ ); } else { document.head.insertAdjacentElement( - 'afterbegin', + 'beforeend', brandThemeVariantLink, ); }