From 3cca2a99fa52926b94c50510b730ece04c4a3703 Mon Sep 17 00:00:00 2001 From: monteri <36768631+monteri@users.noreply.github.com> Date: Sat, 9 Dec 2023 21:08:44 +0200 Subject: [PATCH] fix: update links in head and *isLoaded to true (#534) Co-authored-by: monteri --- src/react/hooks/paragon/useParagonThemeCore.js | 12 +++++++++++- src/react/hooks/paragon/useParagonThemeVariants.js | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/react/hooks/paragon/useParagonThemeCore.js b/src/react/hooks/paragon/useParagonThemeCore.js index f1090d52e..d3b5983bb 100644 --- a/src/react/hooks/paragon/useParagonThemeCore.js +++ b/src/react/hooks/paragon/useParagonThemeCore.js @@ -34,8 +34,9 @@ const useParagonThemeCore = ({ setIsBrandThemeCoreLoaded(true); return; } - const getParagonThemeCoreLink = () => document.head.querySelector('link[data-paragon-theme-core="true"'); + const getParagonThemeCoreLink = () => document.head.querySelector('link[data-paragon-theme-core="true"]'); const existingCoreThemeLink = document.head.querySelector(`link[href='${themeCore.urls.default}']`); + const brandCoreLink = document.head.querySelector(`link[href='${themeCore.urls.brandOverride}']`); if (!existingCoreThemeLink) { const getExistingCoreThemeLinks = (isBrandOverride) => { const coreThemeLinkSelector = `link[data-${isBrandOverride ? 'brand' : 'paragon'}-theme-core="true"]`; @@ -126,6 +127,15 @@ const useParagonThemeCore = ({ } else { setIsBrandThemeCoreLoaded(true); } + } else { + existingCoreThemeLink.rel = 'stylesheet'; + existingCoreThemeLink.removeAttribute('as'); + if (brandCoreLink) { + brandCoreLink.rel = 'stylesheet'; + brandCoreLink.removeAttribute('as'); + } + setIsParagonThemeCoreLoaded(true); + setIsBrandThemeCoreLoaded(true); } }, [themeCore?.urls, onLoad]); }; diff --git a/src/react/hooks/paragon/useParagonThemeVariants.js b/src/react/hooks/paragon/useParagonThemeVariants.js index efb8ef4c5..737129ef9 100644 --- a/src/react/hooks/paragon/useParagonThemeVariants.js +++ b/src/react/hooks/paragon/useParagonThemeVariants.js @@ -187,7 +187,13 @@ const useParagonThemeVariants = ({ } else { const updatedStylesheetRel = generateStylesheetRelAttr(themeVariant); existingThemeVariantLink.rel = updatedStylesheetRel; - existingThemeVariantBrandLink.rel = updatedStylesheetRel; + existingThemeVariantLink.removeAttribute('as'); + if (existingThemeVariantBrandLink) { + existingThemeVariantBrandLink.rel = updatedStylesheetRel; + existingThemeVariantBrandLink.removeAttribute('as'); + } + setIsParagonThemeVariantLoaded(true); + setIsBrandThemeVariantLoaded(true); } }); }, [themeVariants, currentThemeVariant, onLoad]);