[search] avoid loading searchNavigation.chunk on on every page load (#209818)

Part of https://github.com/elastic/kibana/issues/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 <elasticmachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2025-02-07 12:37:21 -07:00 committed by GitHub
parent 8c05633cb8
commit 3ee1fa3f61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 17 deletions

View file

@ -11,13 +11,13 @@ import type { CoreStart, ScopedHistory } from '@kbn/core/public';
import type { ChromeNavLink, EuiSideNavItemTypeEnhanced } from '@kbn/core-chrome-browser';
import type { SolutionNavProps } from '@kbn/shared-ux-page-solution-nav';
import type { ClassicNavItem, ClassicNavItemDeepLink, ClassicNavigationFactoryFn } from './types';
import type { ClassicNavItem, ClassicNavItemDeepLink } from './types';
import { stripTrailingSlash } from './utils';
type DeepLinksMap = Record<string, ChromeNavLink | undefined>;
type SolutionNavItems = SolutionNavProps['items'];
export const classicNavigationFactory: ClassicNavigationFactoryFn = (
export const classicNavigationFactory = (
classicItems: ClassicNavItem[],
core: CoreStart,
history: ScopedHistory<unknown>

View file

@ -20,10 +20,10 @@ import type {
SearchNavigationPluginSetup,
SearchNavigationPluginStart,
ClassicNavItem,
ClassicNavigationFactoryFn,
SearchNavigationSetBreadcrumbsOptions,
AppPluginStartDependencies,
} from './types';
import { classicNavigationFactory } from './classic_navigation';
export class SearchNavigationPlugin
implements Plugin<SearchNavigationPluginSetup, SearchNavigationPluginStart>
@ -33,7 +33,6 @@ export class SearchNavigationPlugin
private baseClassicNavItemsFn: (() => ClassicNavItem[]) | undefined = undefined;
private coreStart: CoreStart | undefined = undefined;
private pluginsStart: AppPluginStartDependencies | undefined = undefined;
private classicNavFactory: ClassicNavigationFactoryFn | undefined = undefined;
private onAppMountHandlers: Array<() => Promise<void>> = [];
private chromeSub: Subscription | undefined;
@ -52,10 +51,6 @@ export class SearchNavigationPlugin
this.currentChromeStyle = value;
});
import('./classic_navigation').then(({ classicNavigationFactory }) => {
this.classicNavFactory = classicNavigationFactory;
});
return {
handleOnAppMount: this.handleOnAppMount.bind(this),
registerOnAppMountHandler: this.registerOnAppMountHandler.bind(this),
@ -97,13 +92,12 @@ export class SearchNavigationPlugin
private useClassicNavigation(history: ScopedHistory<unknown>) {
if (
this.baseClassicNavItemsFn === undefined ||
this.classicNavFactory === undefined ||
this.coreStart === undefined ||
this.currentChromeStyle !== 'classic'
)
return undefined;
return this.classicNavFactory(this.baseClassicNavItemsFn(), this.coreStart, history);
return classicNavigationFactory(this.baseClassicNavItemsFn(), this.coreStart, history);
}
private setBreadcrumbs(

View file

@ -7,7 +7,7 @@
import type { ReactNode } from 'react';
import type { AppDeepLinkId, ChromeBreadcrumb } from '@kbn/core-chrome-browser';
import type { CoreStart, ScopedHistory } from '@kbn/core/public';
import type { ScopedHistory } from '@kbn/core/public';
import type { ServerlessPluginSetup, ServerlessPluginStart } from '@kbn/serverless/public';
import type { SolutionNavProps } from '@kbn/shared-ux-page-solution-nav';
@ -51,12 +51,6 @@ export interface ClassicNavItem {
name?: ReactNode;
}
export type ClassicNavigationFactoryFn = (
items: ClassicNavItem[],
core: CoreStart,
history: ScopedHistory<unknown>
) => SolutionNavProps | undefined;
export interface SearchNavigationSetBreadcrumbsOptions {
// When set to `true` breadcrumbs are only set when chrome style is set to classic.
// This option is for pages who rely on Solution Navigation for breadcrumbs, but still