Skip to content

Commit

Permalink
CB-4485 fix: bundle splitting (#2282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud authored Jan 12, 2024
1 parent dbe2cb5 commit 8fdecdf
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 57 deletions.
4 changes: 4 additions & 0 deletions webapp/packages/core-app/src/Body.m.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
flex-direction: column;
overflow: hidden;
}

.loader {
height: var(--app-height);
}
6 changes: 4 additions & 2 deletions webapp/packages/core-app/src/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export const Body = observer(function Body() {

return (
<DNDProvider>
<Loader suspense>
<Loader className={s(styles, { loader: true })} suspense>
<div ref={ref} className={s(styles, { bodyContent: true }, `theme-${themeService.currentTheme.id}`)}>
<Loader suspense>{Screen && <Screen {...screenService.routerService.params} />}</Loader>
<Loader className={s(styles, { loader: true })} suspense>
{Screen && <Screen {...screenService.routerService.params} />}
</Loader>
<DialogsPortal />
<Notifications />
</div>
Expand Down
10 changes: 10 additions & 0 deletions webapp/packages/core-app/src/BodyLazy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2023 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { importLazyComponent } from '@cloudbeaver/core-utils';

export const BodyLazy = importLazyComponent(() => import('./Body').then(m => m.Body));
2 changes: 1 addition & 1 deletion webapp/packages/core-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from './AppScreen/AppScreenBootstrap';
export * from './AppLocaleService';

// components
export * from './Body';
export * from './BodyLazy';

// Interfaces
export * from './manifest';
19 changes: 9 additions & 10 deletions webapp/packages/core-bootstrap/src/renderLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import { Suspense } from 'react';
import { createRoot, Root } from 'react-dom/client';

import { Body } from '@cloudbeaver/core-app';
import { BodyLazy } from '@cloudbeaver/core-app';
import { DisplayError, ErrorBoundary, Loader, s } from '@cloudbeaver/core-blocks';
import { AppContext, IServiceInjector } from '@cloudbeaver/core-di';

import styles from './renderLayout.m.css';

interface IRender {
Expand Down Expand Up @@ -46,15 +47,13 @@ export function renderLayout(serviceInjector: IServiceInjector): IRender {
},
renderApp() {
this.initRoot().render(
(
<AppContext app={serviceInjector}>
<ErrorBoundary root>
<Suspense fallback={<Loader className={s(styles, { loader: true })} />}>
<Body />
</Suspense>
</ErrorBoundary>
</AppContext>
),
<AppContext app={serviceInjector}>
<ErrorBoundary root>
<Suspense fallback={<Loader className={s(styles, { loader: true })} />}>
<BodyLazy />
</Suspense>
</ErrorBoundary>
</AppContext>,
);
},
renderError(exception?: any) {
Expand Down
6 changes: 6 additions & 0 deletions webapp/packages/core-cli/configs/excludedFromVendor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = [
'react-data-grid',
'react-markdown',
'react-virtualized',
'react-window',
'react-dnd',
'react-dnd-html5-backend',
'@popperjs',
'leaflet',
'react-leaflet',
'wellknown',
Expand Down
1 change: 1 addition & 0 deletions webapp/packages/core-theming/src/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $theme-menu-bar-small-action-radius: 3px !default;
$app-height: 100vh !default;

@mixin css-variables {
--app-height: #{$app-height};
.theme-form-element-radius {
border-radius: $theme-form-element-radius;
}
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
"md5": "^2.3.0",
"mobx": "^6.12.0",
"underscore": "^1.13.6",
"react": "^18.2.0",
"uuid": "^9.0.1"
},
"peerDependencies": {},
"devDependencies": {
"@types/md5": "~2.3.5",
"@types/uuid": "~9.0.7",
"@types/underscore": "^1.11.15",
"@types/react": "^18.2.42",
"typescript": "^5.3.2",
"@types/jest": "^29.5.10"
}
Expand Down
15 changes: 15 additions & 0 deletions webapp/packages/core-utils/src/importLazyComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2023 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import React from 'react';

export function importLazyComponent<TComponent extends React.FC<any>>(componentImporter: () => Promise<TComponent>) {
return React.lazy<TComponent>(async () => {
const component = await componentImporter();
return { default: component };
});
}
1 change: 1 addition & 0 deletions webapp/packages/core-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './Quadtree/index';

export * from './underscore';

export * from './importLazyComponent';
export * from './base64ToBlob';
export * from './blobToBase64';
export * from './base64ToHex';
Expand Down
10 changes: 10 additions & 0 deletions webapp/packages/plugin-codemirror6/src/EditorLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { importLazyComponent } from '@cloudbeaver/core-utils';

export const EditorLoader = importLazyComponent(() => import('./Editor').then(m => m.Editor));
23 changes: 0 additions & 23 deletions webapp/packages/plugin-codemirror6/src/EditorLoader.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export const CellEditor = observer<Pick<RenderEditCellProps<IResultSetRowKey>, '
event.stopPropagation();
};

const editorPortal = dataGridContext.getEditorPortal();

return (
<div
ref={setElementRef}
Expand All @@ -108,7 +110,7 @@ export const CellEditor = observer<Pick<RenderEditCellProps<IResultSetRowKey>, '
onMouseDown={preventClick}
onMouseUp={preventClick}
>
{
{editorPortal &&
createPortal(
<div ref={setPopperRef} className={s(styles, { editor: true })} style={popper.styles.popper} {...popper.attributes.popper}>
<InlineEditor
Expand All @@ -129,9 +131,8 @@ export const CellEditor = observer<Pick<RenderEditCellProps<IResultSetRowKey>, '
onUndo={handleUndo}
/>
</div>,
dataGridContext.getEditorPortal()!,
) as any
}
editorPortal,
)}
</div>
);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
height: 12px;
}
}

& .loader {
height: 24px;
}
}

.textFormatterValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
import { observer } from 'mobx-react-lite';
import { useCallback, useContext, useEffect, useRef } from 'react';

import { getComputed, IconOrImage, s, useS } from '@cloudbeaver/core-blocks';
import { isValidUrl } from '@cloudbeaver/core-utils';
import { getComputed, IconOrImage, Loader, s, useS } from '@cloudbeaver/core-blocks';
import { importLazyComponent, isValidUrl } from '@cloudbeaver/core-utils';
import type { IResultSetRowKey } from '@cloudbeaver/plugin-data-viewer';
import type { RenderCellProps } from '@cloudbeaver/plugin-react-data-grid';

import { EditingContext } from '../../../Editing/EditingContext';
import { CellEditor, IEditorRef } from '../../CellEditor';
import type { IEditorRef } from '../../CellEditor';
import { CellContext } from '../../CellRenderer/CellContext';
import { TableDataContext } from '../../TableDataContext';
import styles from './TextFormatter.m.css';

const CellEditor = importLazyComponent(() => import('../../CellEditor').then(module => module.CellEditor));

export const TextFormatter = observer<RenderCellProps<IResultSetRowKey>>(function TextFormatter({ row, column }) {
const editorRef = useRef<IEditorRef>(null);
const editingContext = useContext(EditingContext);
Expand Down Expand Up @@ -53,7 +55,9 @@ export const TextFormatter = observer<RenderCellProps<IResultSetRowKey>>(functio
if (cellContext.isEditing) {
return (
<div className={classes}>
<CellEditor ref={editorRef} row={row} column={column} onClose={handleClose} />
<Loader className={s(style, { loader: true })} suspense small>
<CellEditor ref={editorRef} row={row} column={column} onClose={handleClose} />
</Loader>
</div>
);
}
Expand Down
10 changes: 7 additions & 3 deletions webapp/packages/plugin-ddl-viewer/src/DdlViewerBootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
*/
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { EObjectFeature, NavNodeInfoResource } from '@cloudbeaver/core-navigation-tree';
import { importLazyComponent } from '@cloudbeaver/core-utils';
import { NavNodeViewService } from '@cloudbeaver/plugin-navigation-tree';

import { DDLViewerFooterService } from './DdlViewer/DDLViewerFooterService';
import { DDLViewerTab } from './DdlViewer/DDLViewerTab';
import { DDLViewerTabPanel } from './DdlViewer/DDLViewerTabPanel';
import { ExtendedDDLViewerTabPanel } from './ExtendedDDLViewer/ExtendedDDLViewerTabPanel';
import { NAV_NODE_DDL_ID } from './NAV_NODE_DDL_ID';
import { NAV_NODE_EXTENDED_DDL_ID } from './NAV_NODE_EXTENDED_DDL_ID';

const DDLViewerTab = importLazyComponent(() => import('./DdlViewer/DDLViewerTab').then(m => m.DDLViewerTab));
const DDLViewerTabPanel = importLazyComponent(() => import('./DdlViewer/DDLViewerTabPanel').then(m => m.DDLViewerTabPanel));
const ExtendedDDLViewerTabPanel = importLazyComponent(() =>
import('./ExtendedDDLViewer/ExtendedDDLViewerTabPanel').then(m => m.ExtendedDDLViewerTabPanel),
);

@injectable()
export class DdlViewerBootstrap extends Bootstrap {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { observer } from 'mobx-react-lite';
import { forwardRef } from 'react';

import { EditorLoader, IDefaultExtensions, IEditorProps, IEditorRef } from '@cloudbeaver/plugin-codemirror6';
import { EditorLoader, type IDefaultExtensions, type IEditorProps, type IEditorRef } from '@cloudbeaver/plugin-codemirror6';

export const SQLCodeEditor = observer<IEditorProps & IDefaultExtensions, IEditorRef>(
forwardRef(function SQLCodeEditor(props, ref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
* you may not use this file except in compliance with the License.
*/
import { observer } from 'mobx-react-lite';
import React from 'react';
import styled, { css } from 'reshadow';

import { importLazyComponent } from '@cloudbeaver/core-utils';

import type { ISqlEditorTabState } from '../ISqlEditorTabState';
import { SqlExecutionPlanPanel } from './ExecutionPlan/SqlExecutionPlanPanel';
import { OutputLogsPanel } from './OutputLogs/OutputLogsPanel';
import { SqlResultSetPanel } from './SqlResultSetPanel';
import { SqlScriptStatisticsPanel } from './SqlScriptStatisticsPanel';

const SqlExecutionPlanPanel = importLazyComponent(() => import('./ExecutionPlan/SqlExecutionPlanPanel').then(module => module.SqlExecutionPlanPanel));
const OutputLogsPanel = importLazyComponent(() => import('./OutputLogs/OutputLogsPanel').then(module => module.OutputLogsPanel));
const SqlResultSetPanel = importLazyComponent(() => import('./SqlResultSetPanel').then(module => module.SqlResultSetPanel));
const SqlScriptStatisticsPanel = importLazyComponent(() => import('./SqlScriptStatisticsPanel').then(module => module.SqlScriptStatisticsPanel));

const style = css`
result-panel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { injectable } from '@cloudbeaver/core-di';
import { CommonDialogService } from '@cloudbeaver/core-dialogs';
import { NotificationService } from '@cloudbeaver/core-events';
import { GraphQLService, ResultDataFormat, UpdateResultsDataBatchScriptMutationVariables } from '@cloudbeaver/core-sdk';
import { importLazyComponent } from '@cloudbeaver/core-utils';
import { DocumentEditAction, type IDatabaseDataModel, ResultSetEditAction } from '@cloudbeaver/plugin-data-viewer';

import { ScriptPreviewDialog } from './ScriptPreviewDialog';
const ScriptPreviewDialog = importLazyComponent(() => import('./ScriptPreviewDialog').then(m => m.ScriptPreviewDialog));

@injectable()
export class ScriptPreviewService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { CommonDialogService } from '@cloudbeaver/core-dialogs';
import { DATA_CONTEXT_NAV_NODE, EObjectFeature } from '@cloudbeaver/core-navigation-tree';
import { getCachedMapResourceLoaderState } from '@cloudbeaver/core-resource';
import { importLazyComponent } from '@cloudbeaver/core-utils';
import { DATA_CONTEXT_MENU, DATA_CONTEXT_MENU_NESTED, MenuBaseItem, MenuService } from '@cloudbeaver/core-view';

import { GeneratedSqlDialog } from './GeneratedSqlDialog';
import { MENU_SQL_GENERATORS } from './MENU_SQL_GENERATORS';
import { SqlGeneratorsResource } from './SqlGeneratorsResource';

const GeneratedSqlDialog = importLazyComponent(() => import('./GeneratedSqlDialog').then(m => m.GeneratedSqlDialog));

@injectable()
export class SqlGeneratorsBootstrap extends Bootstrap {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
*/
import { AdministrationItemService, AdministrationItemType } from '@cloudbeaver/core-administration';
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { importLazyComponent } from '@cloudbeaver/core-utils';
import { VersionUpdateService } from '@cloudbeaver/core-version-update';

import { DockerUpdateInstructions } from './DockerUpdateInstructions';
import { VersionUpdate } from './VersionUpdate';
import { VersionUpdateDrawerItem } from './VersionUpdateDrawerItem';
const DockerUpdateInstructions = importLazyComponent(() => import('./DockerUpdateInstructions').then(m => m.DockerUpdateInstructions));
const VersionUpdate = importLazyComponent(() => import('./VersionUpdate').then(m => m.VersionUpdate));
const VersionUpdateDrawerItem = importLazyComponent(() => import('./VersionUpdateDrawerItem').then(m => m.VersionUpdateDrawerItem));

@injectable()
export class PluginBootstrap extends Bootstrap {
Expand Down

0 comments on commit 8fdecdf

Please sign in to comment.