Skip to content

Commit

Permalink
[docs]: add globalInjectThemeCache to avoid unnecessary jsx dynamic i…
Browse files Browse the repository at this point in the history
…mport and theme getting
  • Loading branch information
Vxee committed Aug 1, 2024
1 parent b8815f0 commit c45e63d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions docs/src/modules/components/DemoSandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const iframeDefaultJoyTheme = extendTheme({
cssVarPrefix: 'demo-iframe',
});

let globalInjectThemeCache;

function FramedDemo(props) {
const { children, document, usesCssVarsTheme } = props;

Expand Down Expand Up @@ -208,11 +210,13 @@ function DemoSandbox(props) {
useEnhancedEffect(() => {
async function setupMaterialUITheme() {
if (typeof window.getInjectTheme === 'function') {
window.React = React;
const jsx = await import('react/jsx-runtime');
window.jsx = jsx;
const themeOptions = window.getInjectTheme();
setInjectTheme(themeOptions);
if (!globalInjectThemeCache) {
window.React = React;
const jsx = await import('react/jsx-runtime');
window.jsx = jsx;
globalInjectThemeCache = window.getInjectTheme();
}
setInjectTheme(globalInjectThemeCache);
}
}
setupMaterialUITheme();
Expand Down

0 comments on commit c45e63d

Please sign in to comment.