Skip to content

Commit a214631

Browse files
authored
[APM] Lazy-load alert triggers (#68806) (#68830)
Use `React.lazy` to load the alert triggers so the code doesn't load until the alert flyout is opened. Fixes #66189.
1 parent 29380dc commit a214631

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

x-pack/plugins/apm/public/components/shared/ErrorRateAlertTrigger/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,8 @@ export function ErrorRateAlertTrigger(props: Props) {
116116
/>
117117
);
118118
}
119+
120+
// Default export is required for React.lazy loading
121+
//
122+
// eslint-disable-next-line import/no-default-export
123+
export default ErrorRateAlertTrigger;

x-pack/plugins/apm/public/components/shared/TransactionDurationAlertTrigger/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,8 @@ export function TransactionDurationAlertTrigger(props: Props) {
175175
/>
176176
);
177177
}
178+
179+
// Default export is required for React.lazy loading
180+
//
181+
// eslint-disable-next-line import/no-default-export
182+
export default TransactionDurationAlertTrigger;

x-pack/plugins/apm/public/plugin.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,38 @@
55
*/
66

77
import { i18n } from '@kbn/i18n';
8+
import { lazy } from 'react';
9+
import { ConfigSchema } from '.';
810
import {
911
AppMountParameters,
1012
CoreSetup,
1113
CoreStart,
14+
DEFAULT_APP_CATEGORIES,
1215
Plugin,
1316
PluginInitializerContext,
1417
} from '../../../../src/core/public';
15-
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/public';
16-
17-
import {
18-
PluginSetupContract as AlertingPluginPublicSetup,
19-
PluginStartContract as AlertingPluginPublicStart,
20-
} from '../../alerts/public';
21-
import { FeaturesPluginSetup } from '../../features/public';
2218
import {
2319
DataPublicPluginSetup,
2420
DataPublicPluginStart,
2521
} from '../../../../src/plugins/data/public';
2622
import { HomePublicPluginSetup } from '../../../../src/plugins/home/public';
23+
import {
24+
PluginSetupContract as AlertingPluginPublicSetup,
25+
PluginStartContract as AlertingPluginPublicStart,
26+
} from '../../alerts/public';
27+
import { FeaturesPluginSetup } from '../../features/public';
2728
import { LicensingPluginSetup } from '../../licensing/public';
2829
import {
2930
TriggersAndActionsUIPublicPluginSetup,
3031
TriggersAndActionsUIPublicPluginStart,
3132
} from '../../triggers_actions_ui/public';
32-
import { ConfigSchema } from '.';
33-
import { createCallApmApi } from './services/rest/createCallApmApi';
34-
import { featureCatalogueEntry } from './featureCatalogueEntry';
3533
import { AlertType } from '../common/alert_types';
36-
import { ErrorRateAlertTrigger } from './components/shared/ErrorRateAlertTrigger';
37-
import { TransactionDurationAlertTrigger } from './components/shared/TransactionDurationAlertTrigger';
34+
import { featureCatalogueEntry } from './featureCatalogueEntry';
35+
import { createCallApmApi } from './services/rest/createCallApmApi';
36+
import { createStaticIndexPattern } from './services/rest/index_pattern';
3837
import { setHelpExtension } from './setHelpExtension';
3938
import { toggleAppLinkInNav } from './toggleAppLinkInNav';
4039
import { setReadonlyBadge } from './updateBadge';
41-
import { createStaticIndexPattern } from './services/rest/index_pattern';
4240

4341
export type ApmPluginSetup = void;
4442
export type ApmPluginStart = void;
@@ -112,7 +110,9 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
112110
defaultMessage: 'Error rate',
113111
}),
114112
iconClass: 'bell',
115-
alertParamsExpression: ErrorRateAlertTrigger,
113+
alertParamsExpression: lazy(() =>
114+
import('./components/shared/ErrorRateAlertTrigger')
115+
),
116116
validate: () => ({
117117
errors: [],
118118
}),
@@ -125,7 +125,9 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
125125
defaultMessage: 'Transaction duration',
126126
}),
127127
iconClass: 'bell',
128-
alertParamsExpression: TransactionDurationAlertTrigger,
128+
alertParamsExpression: lazy(() =>
129+
import('./components/shared/TransactionDurationAlertTrigger')
130+
),
129131
validate: () => ({
130132
errors: [],
131133
}),

0 commit comments

Comments
 (0)