fix: redundant style injections for multiple repls
This commit is contained in:
parent
20e8a30583
commit
48e06bd213
2 changed files with 11 additions and 4 deletions
14
packages/codemirror/themes.mjs
vendored
14
packages/codemirror/themes.mjs
vendored
|
|
@ -484,11 +484,16 @@ export function injectStyle(rule) {
|
||||||
return () => styleSheet.deleteRule(ruleIndex);
|
return () => styleSheet.deleteRule(ruleIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentTheme, resetThemeStyle, themeStyle;
|
let currentTheme,
|
||||||
|
resetThemeStyle,
|
||||||
|
themeStyle,
|
||||||
|
styleID = 'strudel-theme-vars';
|
||||||
export function initTheme(theme) {
|
export function initTheme(theme) {
|
||||||
themeStyle = document.createElement('style');
|
if (!document.getElementById(styleID)) {
|
||||||
themeStyle.id = 'strudel-theme';
|
themeStyle = document.createElement('style');
|
||||||
document.head.append(themeStyle);
|
themeStyle.id = styleID;
|
||||||
|
document.head.append(themeStyle);
|
||||||
|
}
|
||||||
activateTheme(theme);
|
activateTheme(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -496,6 +501,7 @@ export function activateTheme(name) {
|
||||||
if (currentTheme === name) {
|
if (currentTheme === name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
currentTheme = name;
|
||||||
if (!settings[name]) {
|
if (!settings[name]) {
|
||||||
console.warn('theme', name, 'has no settings.. defaulting to strudelTheme settings');
|
console.warn('theme', name, 'has no settings.. defaulting to strudelTheme settings');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ export function MicroRepl({ code, hideHeader = false }) {
|
||||||
<div className="overflow-auto relative">
|
<div className="overflow-auto relative">
|
||||||
<strudel-editor
|
<strudel-editor
|
||||||
is-line-numbers-displayed="0"
|
is-line-numbers-displayed="0"
|
||||||
|
is-active-line-highlighted="0"
|
||||||
code={code}
|
code={code}
|
||||||
ref={(el) => {
|
ref={(el) => {
|
||||||
if (wc.current) {
|
if (wc.current) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue