Skip to content

Commit

Permalink
[docs] Add cache to avoid unnecessary jsx dynamic import and theme ge…
Browse files Browse the repository at this point in the history
…tting (#43139)
  • Loading branch information
Vxee authored Aug 19, 2024
1 parent f7237d8 commit f62954b
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 f62954b

Please sign in to comment.