Skip to content

Commit

Permalink
fix: Fix loading of stylesheet when it's already preloaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
xitij2000 authored and ArturGaspar committed Jul 29, 2024
1 parent 24acfac commit 0b3c440
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/react/AppProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default function AppProvider({ store, children, wrapWithRouter }) {
return null;
}

console.log({locale});

return (
<IntlProvider locale={locale} messages={getMessages()}>
<ErrorBoundary>
Expand Down
7 changes: 4 additions & 3 deletions src/react/hooks/paragon/useParagonThemeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const useParagonThemeCore = ({
setIsBrandThemeCoreLoaded(true);
return;
}
const getParagonThemeCoreLink = () => document.head.querySelector('link[data-paragon-theme-core="true"');
const existingCoreThemeLink = document.head.querySelector(`link[href='${themeCore.urls.default}']`);
const getParagonThemeCoreLink = () => document.head.querySelector('link[data-paragon-theme-core="true"][rel=stylesheet]');
const existingCoreThemeLink = document.head.querySelector(`link[href='${themeCore.urls.default}'][rel=stylesheet]`);
if (!existingCoreThemeLink) {
const getExistingCoreThemeLinks = (isBrandOverride) => {
const coreThemeLinkSelector = `link[data-${isBrandOverride ? 'brand' : 'paragon'}-theme-core="true"]`;
const coreThemeLinkSelector = `link[data-${isBrandOverride ? 'brand' : 'paragon'}-theme-core="true"][rel=stylesheet]`;
return document.head.querySelectorAll(coreThemeLinkSelector);
};
const createCoreThemeLink = (
Expand Down Expand Up @@ -131,3 +131,4 @@ const useParagonThemeCore = ({
};

export default useParagonThemeCore;

8 changes: 4 additions & 4 deletions src/react/hooks/paragon/useParagonThemeVariants.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ const useParagonThemeVariants = ({
setIsBrandThemeVariantLoaded(true);
return;
}
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}']`);
const getParagonThemeVariantLink = () => document.head.querySelector(`link[data-paragon-theme-variant='${themeVariant}'][rel=stylesheet]`);
const existingThemeVariantLink = document.head.querySelector(`link[href='${value.urls.default}'][rel=stylesheet]`);
const existingThemeVariantBrandLink = document.head.querySelector(`link[href='${value.urls.brandOverride}'][rel=stylesheet]`);

const getExistingThemeVariantLinks = (isBrandOverride) => {
const themeVariantLinkSelector = `link[data-${isBrandOverride ? 'brand' : 'paragon'}-theme-variant='${themeVariant}']`;
const themeVariantLinkSelector = `link[data-${isBrandOverride ? 'brand' : 'paragon'}-theme-variant='${themeVariant}'][rel=stylesheet]`;
return document.head.querySelectorAll(themeVariantLinkSelector);
};

Expand Down

0 comments on commit 0b3c440

Please sign in to comment.