Skip to content

Commit b34a8f2

Browse files
authored
fix: prevent multiply calls of render function (#768)
1 parent 6a8e109 commit b34a8f2

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/services/instanceService.tsx

+24-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default class InstanceService
3131
defaultLocale: 'en',
3232
};
3333

34+
private rendered = false;
35+
3436
constructor(config: IConfigProps) {
3537
super();
3638
if (config.defaultLocale) {
@@ -59,25 +61,28 @@ export default class InstanceService
5961
};
6062

6163
public render = (workbench: ReactElement) => {
62-
this.emit(InstanceHookKind.beforeInit);
63-
64-
// get all locales including builtin and custom locales
65-
const [languages, others] = molecule.extension.splitLanguagesExts(
66-
this._config.extensions
67-
);
68-
this.initialLocaleService(languages);
69-
70-
// resolve all controllers, and call `initView` to inject initial values into services
71-
Object.keys(controllers).forEach((key) => {
72-
const module = controllers[key];
73-
const controller = container.resolve<Controller>(module);
74-
controller.initView?.();
75-
});
76-
77-
this.emit(InstanceHookKind.beforeLoad);
78-
molecule.extension.load(others);
79-
80-
molecule.monacoService.initWorkspace(molecule.layout.container!);
64+
if (!this.rendered) {
65+
this.emit(InstanceHookKind.beforeInit);
66+
67+
// get all locales including builtin and custom locales
68+
const [languages, others] = molecule.extension.splitLanguagesExts(
69+
this._config.extensions
70+
);
71+
this.initialLocaleService(languages);
72+
73+
// resolve all controllers, and call `initView` to inject initial values into services
74+
Object.keys(controllers).forEach((key) => {
75+
const module = controllers[key];
76+
const controller = container.resolve<Controller>(module);
77+
controller.initView?.();
78+
});
79+
80+
this.emit(InstanceHookKind.beforeLoad);
81+
molecule.extension.load(others);
82+
83+
molecule.monacoService.initWorkspace(molecule.layout.container!);
84+
this.rendered = true;
85+
}
8186

8287
return workbench;
8388
};

0 commit comments

Comments
 (0)