Skip to content

Commit 6ab4be5

Browse files
Robert AustinXavierM
andauthored
[Security Solution] Reduce initial bundle size (#78992)
* Load the redux store factory and initial state factory lazily * Combine certain dynamic imports to reduce total async bundle size (this works because shared dependencies between async chunks are not being de-duped by Webpack.) * Add explicit types in some areas. Co-authored-by: Xavier Mouligneau <[email protected]>
1 parent 8d0a96a commit 6ab4be5

File tree

7 files changed

+296
-253
lines changed

7 files changed

+296
-253
lines changed

x-pack/plugins/security_solution/public/app/index.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,10 @@
55
*/
66

77
import React from 'react';
8-
import { Store, Action } from 'redux';
98
import { render, unmountComponentAtNode } from 'react-dom';
109

11-
import { AppMountParameters } from '../../../../../src/core/public';
12-
import { State } from '../common/store';
13-
import { StartServices } from '../types';
1410
import { SecurityApp } from './app';
15-
import { AppFrontendLibs } from '../common/lib/lib';
16-
17-
interface RenderAppProps extends AppFrontendLibs, AppMountParameters {
18-
services: StartServices;
19-
store: Store<State, Action>;
20-
SubPluginRoutes: React.FC;
21-
}
11+
import { RenderAppProps } from './types';
2212

2313
export const renderApp = ({
2414
apolloClient,
@@ -27,7 +17,7 @@ export const renderApp = ({
2717
services,
2818
store,
2919
SubPluginRoutes,
30-
}: RenderAppProps) => {
20+
}: RenderAppProps): (() => void) => {
3121
render(
3222
<SecurityApp apolloClient={apolloClient} history={history} services={services} store={store}>
3323
<SubPluginRoutes />

x-pack/plugins/security_solution/public/app/types.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@ import {
88
Reducer,
99
AnyAction,
1010
Middleware,
11+
Action,
12+
Store,
1113
Dispatch,
1214
PreloadedState,
1315
StateFromReducersMapObject,
1416
CombinedState,
1517
} from 'redux';
1618

19+
import { AppMountParameters } from '../../../../../src/core/public';
20+
import { StartServices } from '../types';
21+
import { AppFrontendLibs } from '../common/lib/lib';
22+
23+
/**
24+
* The React properties used to render `SecurityApp` as well as the `element` to render it into.
25+
*/
26+
export interface RenderAppProps extends AppFrontendLibs, AppMountParameters {
27+
services: StartServices;
28+
store: Store<State, Action>;
29+
SubPluginRoutes: React.FC;
30+
}
31+
1732
import { State, SubPluginsInitReducer } from '../common/store';
1833
import { Immutable } from '../../common/endpoint/types';
1934
import { AppAction } from '../common/store/actions';
@@ -31,7 +46,7 @@ export interface SecuritySubPlugin {
3146
storageTimelines?: Pick<TimelineState, 'timelineById'>;
3247
}
3348

34-
type SecuritySubPluginKeyStore =
49+
export type SecuritySubPluginKeyStore =
3550
| 'hosts'
3651
| 'network'
3752
| 'timeline'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
/**
8+
* the plugin (defined in `plugin.tsx`) has many dependencies that can be loaded only when the app is being used.
9+
* By loading these later we can reduce the initial bundle size and allow users to delay loading these dependencies until they are needed.
10+
*/
11+
12+
import { renderApp } from './app';
13+
import { composeLibs } from './common/lib/compose/kibana_compose';
14+
15+
import { createStore, createInitialState } from './common/store';
16+
17+
export { renderApp, composeLibs, createStore, createInitialState };
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
/**
8+
* the plugin (defined in `plugin.tsx`) has many dependencies that can be loaded only when the app is being used.
9+
* By loading these later we can reduce the initial bundle size and allow users to delay loading these dependencies until they are needed.
10+
*/
11+
12+
import { Detections } from './detections';
13+
import { Cases } from './cases';
14+
import { Hosts } from './hosts';
15+
import { Network } from './network';
16+
import { Overview } from './overview';
17+
import { Timelines } from './timelines';
18+
import { Management } from './management';
19+
20+
/**
21+
* The classes used to instantiate the sub plugins. These are grouped into a single object for the sake of bundling them in a single dynamic import.
22+
*/
23+
const subPluginClasses = {
24+
Detections,
25+
Cases,
26+
Hosts,
27+
Network,
28+
Overview,
29+
Timelines,
30+
Management,
31+
};
32+
export { subPluginClasses };

0 commit comments

Comments
 (0)