Skip to content

Commit 6bb3239

Browse files
author
轻游
committed
PullRequest: 113 fix: 组件重新渲染时序问题
1 parent e1353e2 commit 6bb3239

3 files changed

Lines changed: 42 additions & 20 deletions

File tree

packages/acr/src/modules/merge-request/merge-request.contribution.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,7 @@ export class MergeRequestContribution
4444
}
4545

4646
onDidStart() {
47-
// 重新载入会导致组件未注册 临时修复
48-
const tabbarService = this.layoutService.getTabbarService(SlotLocation.left);
49-
const componentRegistry =
50-
this.componentRegistry.getComponentRegistryInfo(MergeRequestExplorerId);
51-
if (componentRegistry) {
52-
tabbarService.registerContainer(MergeRequestExplorerId, componentRegistry);
53-
const state = this.layoutState.getState(LAYOUT_STATE.MAIN, {});
54-
let currentId: string,
55-
size: number = 0,
56-
show = true;
57-
for (const key in state) {
58-
if (key === SlotLocation.left) {
59-
currentId = state[key]?.currentId;
60-
size = state[key]?.size || 0;
61-
show = currentId ? true : false;
62-
}
63-
}
64-
this.layoutService.toggleSlot(SlotLocation.left, show, size);
65-
}
66-
// 重新载入 titleMenu有缓存 需将其重置
47+
// TODO 重新载入 titleMenu有缓存 需将其重置
6748
disposableCollection.push((injector) => {
6849
const accordionService: AccordionService = injector
6950
.get(IMainLayoutService)

packages/core/src/client/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { EditorEmptyContribution } from './editor-empty/editor-empty.contributio
3030
import { WelcomeContribution } from './welcome/welcome.contributon';
3131
import { FileSchemeContribution } from './file-scheme/index.contribution';
3232
import { PreferenceSettingContribution } from './preference/preference.setting.contribution';
33+
import { LayoutRestoreContributation } from './layout/index.contribution';
3334

3435
import {
3536
MonacoCodeService,
@@ -71,6 +72,7 @@ export class ClientModule extends BrowserModule {
7172
FileSchemeContribution,
7273
SearchContribution,
7374
PreferenceSettingContribution,
75+
LayoutRestoreContributation,
7476
{
7577
token: MonacoCodeService,
7678
useValue: codeServiceEditor,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Autowired } from '@opensumi/di';
2+
import {
3+
CommandRegistry,
4+
SlotLocation,
5+
ClientAppContribution,
6+
AppConfig,
7+
ComponentRegistry,
8+
} from '@opensumi/ide-core-browser';
9+
import { Domain } from '@opensumi/ide-core-common';
10+
import { IMainLayoutService } from '@opensumi/ide-main-layout';
11+
12+
@Domain(ClientAppContribution)
13+
//TODO 组件卸载重新渲染 渲染时注册container 会有时序问题 临时修复
14+
export class LayoutRestoreContributation implements ClientAppContribution {
15+
@Autowired(AppConfig)
16+
private appConfig: AppConfig;
17+
@Autowired(IMainLayoutService)
18+
layoutService: IMainLayoutService;
19+
@Autowired(ComponentRegistry)
20+
componentRegistry: ComponentRegistry;
21+
async onDidStart() {
22+
const layoutConfig = this.appConfig.layoutConfig;
23+
const layoutDirection = [SlotLocation.left, SlotLocation.bottom, SlotLocation.right];
24+
layoutDirection.forEach((direction) => {
25+
const tabbarService = this.layoutService.getTabbarService(direction);
26+
layoutConfig[direction]?.modules.forEach((module) => {
27+
const componentRegistry = this.componentRegistry.getComponentRegistryInfo(module);
28+
if (componentRegistry) {
29+
tabbarService.registerContainer(
30+
componentRegistry.options!.containerId,
31+
componentRegistry
32+
);
33+
}
34+
});
35+
// @ts-ignore
36+
this.layoutService.restoreTabbarService(tabbarService);
37+
});
38+
}
39+
}

0 commit comments

Comments
 (0)