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 committed Nov 14, 2023
1 parent cf10278 commit 9aa4fa6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"lodash.merge": "4.6.2",
"lodash.snakecase": "4.1.1",
"pubsub-js": "1.9.4",
"react-intl": "5.25.1",
"react-intl": "^5.25.1",
"universal-cookie": "4.0.4"
},
"peerDependencies": {
Expand Down
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 }) {
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 9aa4fa6

Please sign in to comment.