Skip to content

Commit c45e63d

Browse files
committed
[docs]: add globalInjectThemeCache to avoid unnecessary jsx dynamic import and theme getting
1 parent b8815f0 commit c45e63d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/src/modules/components/DemoSandbox.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const iframeDefaultJoyTheme = extendTheme({
2121
cssVarPrefix: 'demo-iframe',
2222
});
2323

24+
let globalInjectThemeCache;
25+
2426
function FramedDemo(props) {
2527
const { children, document, usesCssVarsTheme } = props;
2628

@@ -208,11 +210,13 @@ function DemoSandbox(props) {
208210
useEnhancedEffect(() => {
209211
async function setupMaterialUITheme() {
210212
if (typeof window.getInjectTheme === 'function') {
211-
window.React = React;
212-
const jsx = await import('react/jsx-runtime');
213-
window.jsx = jsx;
214-
const themeOptions = window.getInjectTheme();
215-
setInjectTheme(themeOptions);
213+
if (!globalInjectThemeCache) {
214+
window.React = React;
215+
const jsx = await import('react/jsx-runtime');
216+
window.jsx = jsx;
217+
globalInjectThemeCache = window.getInjectTheme();
218+
}
219+
setInjectTheme(globalInjectThemeCache);
216220
}
217221
}
218222
setupMaterialUITheme();

0 commit comments

Comments
 (0)