Skip to content

Commit 3ee1fa3

Browse files
[search] avoid loading searchNavigation.chunk on on every page load (#209818)
Part of #194171 PR removes all async imports run during searchNavigation plugin setup and start methods. ### Test instructions * Start kibana locally * Open network tab in browser * Open home page. Verify `searchNavigation.chunk` are not loaded. The screen shots show the behavior in main where `searchNavigation.chunk` are loaded on home page <img width="600" alt="Screenshot 2025-02-05 at 9 20 21 AM" src="https://github.com/user-attachments/assets/e718e18e-de6e-4c1e-ba28-af713440459c" /> --------- Co-authored-by: Elastic Machine <[email protected]>
1 parent 8c05633 commit 3ee1fa3

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

x-pack/solutions/search/plugins/search_solution/search_navigation/public/classic_navigation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import type { CoreStart, ScopedHistory } from '@kbn/core/public';
1111
import type { ChromeNavLink, EuiSideNavItemTypeEnhanced } from '@kbn/core-chrome-browser';
1212
import type { SolutionNavProps } from '@kbn/shared-ux-page-solution-nav';
1313

14-
import type { ClassicNavItem, ClassicNavItemDeepLink, ClassicNavigationFactoryFn } from './types';
14+
import type { ClassicNavItem, ClassicNavItemDeepLink } from './types';
1515
import { stripTrailingSlash } from './utils';
1616

1717
type DeepLinksMap = Record<string, ChromeNavLink | undefined>;
1818
type SolutionNavItems = SolutionNavProps['items'];
1919

20-
export const classicNavigationFactory: ClassicNavigationFactoryFn = (
20+
export const classicNavigationFactory = (
2121
classicItems: ClassicNavItem[],
2222
core: CoreStart,
2323
history: ScopedHistory<unknown>

x-pack/solutions/search/plugins/search_solution/search_navigation/public/plugin.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import type {
2020
SearchNavigationPluginSetup,
2121
SearchNavigationPluginStart,
2222
ClassicNavItem,
23-
ClassicNavigationFactoryFn,
2423
SearchNavigationSetBreadcrumbsOptions,
2524
AppPluginStartDependencies,
2625
} from './types';
26+
import { classicNavigationFactory } from './classic_navigation';
2727

2828
export class SearchNavigationPlugin
2929
implements Plugin<SearchNavigationPluginSetup, SearchNavigationPluginStart>
@@ -33,7 +33,6 @@ export class SearchNavigationPlugin
3333
private baseClassicNavItemsFn: (() => ClassicNavItem[]) | undefined = undefined;
3434
private coreStart: CoreStart | undefined = undefined;
3535
private pluginsStart: AppPluginStartDependencies | undefined = undefined;
36-
private classicNavFactory: ClassicNavigationFactoryFn | undefined = undefined;
3736
private onAppMountHandlers: Array<() => Promise<void>> = [];
3837
private chromeSub: Subscription | undefined;
3938

@@ -52,10 +51,6 @@ export class SearchNavigationPlugin
5251
this.currentChromeStyle = value;
5352
});
5453

55-
import('./classic_navigation').then(({ classicNavigationFactory }) => {
56-
this.classicNavFactory = classicNavigationFactory;
57-
});
58-
5954
return {
6055
handleOnAppMount: this.handleOnAppMount.bind(this),
6156
registerOnAppMountHandler: this.registerOnAppMountHandler.bind(this),
@@ -97,13 +92,12 @@ export class SearchNavigationPlugin
9792
private useClassicNavigation(history: ScopedHistory<unknown>) {
9893
if (
9994
this.baseClassicNavItemsFn === undefined ||
100-
this.classicNavFactory === undefined ||
10195
this.coreStart === undefined ||
10296
this.currentChromeStyle !== 'classic'
10397
)
10498
return undefined;
10599

106-
return this.classicNavFactory(this.baseClassicNavItemsFn(), this.coreStart, history);
100+
return classicNavigationFactory(this.baseClassicNavItemsFn(), this.coreStart, history);
107101
}
108102

109103
private setBreadcrumbs(

x-pack/solutions/search/plugins/search_solution/search_navigation/public/types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import type { ReactNode } from 'react';
99
import type { AppDeepLinkId, ChromeBreadcrumb } from '@kbn/core-chrome-browser';
10-
import type { CoreStart, ScopedHistory } from '@kbn/core/public';
10+
import type { ScopedHistory } from '@kbn/core/public';
1111
import type { ServerlessPluginSetup, ServerlessPluginStart } from '@kbn/serverless/public';
1212
import type { SolutionNavProps } from '@kbn/shared-ux-page-solution-nav';
1313

@@ -51,12 +51,6 @@ export interface ClassicNavItem {
5151
name?: ReactNode;
5252
}
5353

54-
export type ClassicNavigationFactoryFn = (
55-
items: ClassicNavItem[],
56-
core: CoreStart,
57-
history: ScopedHistory<unknown>
58-
) => SolutionNavProps | undefined;
59-
6054
export interface SearchNavigationSetBreadcrumbsOptions {
6155
// When set to `true` breadcrumbs are only set when chrome style is set to classic.
6256
// This option is for pages who rely on Solution Navigation for breadcrumbs, but still

0 commit comments

Comments
 (0)