Skip to content

Commit de933a1

Browse files
committedOct 21, 2024
fix theme switching
1 parent 97c5222 commit de933a1

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed
 

‎packages/home/settings.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,13 @@ class SettingsController {
201201
setTimeFormat(value);
202202
}
203203

204+
onThemeSwitchedTimeout: any;
205+
204206
switchTheme(value: boolean) {
207+
if (this.onThemeSwitchedTimeout) {
208+
return;
209+
}
210+
205211
this.isDarkTheme = value;
206212
setIsDarkTheme(value);
207213
this.onThemeSwitched();
@@ -238,9 +244,10 @@ class SettingsController {
238244
"../../node_modules/flexlayout-react/style/light.css";
239245
}
240246

241-
setTimeout(() => {
247+
this.onThemeSwitchedTimeout = setTimeout(() => {
248+
this.onThemeSwitchedTimeout = undefined;
242249
content.style.opacity = "";
243-
}, 200);
250+
}, 500);
244251
}
245252

246253
removeItemFromMRU(mruItem: IMruItem) {

‎packages/project-editor/flow/editor/render.tsx

+14-8
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ export const ComponentEnclosure = observer(
179179
return;
180180
}
181181

182-
if (this.updateComponentTimeout) {
183-
clearTimeout(this.updateComponentTimeout);
184-
this.updateComponentTimeout = undefined;
185-
}
186-
187182
if (this.elRef.current && this.listIndex == 0) {
188183
const component = this.props.component;
189184
if (component instanceof ProjectEditor.PageClass) {
@@ -198,7 +193,6 @@ export const ComponentEnclosure = observer(
198193

199194
if (this.elRef.current.offsetParent == null) {
200195
// do not calculate geometry if element is not visible
201-
202196
this.updateComponentTimeout = setTimeout(() => {
203197
this.updateComponentTimeout = undefined;
204198
this.updateComponentGeometry();
@@ -221,12 +215,24 @@ export const ComponentEnclosure = observer(
221215
}
222216
};
223217

218+
debounceUpdateComponentGeometry = () => {
219+
if (this.updateComponentTimeout) {
220+
clearTimeout(this.updateComponentTimeout);
221+
this.updateComponentTimeout = undefined;
222+
}
223+
224+
this.updateComponentTimeout = setTimeout(() => {
225+
this.updateComponentTimeout = undefined;
226+
this.updateComponentGeometry();
227+
});
228+
};
229+
224230
componentDidMount() {
225-
this.updateComponentGeometry();
231+
this.debounceUpdateComponentGeometry();
226232
}
227233

228234
componentDidUpdate() {
229-
this.updateComponentGeometry();
235+
this.debounceUpdateComponentGeometry();
230236
}
231237

232238
componentWillUnmount() {

0 commit comments

Comments
 (0)