From 1d84ed948c31c951d635fca1c468e5f3ed32dc4c Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 1 Jul 2024 15:53:54 -0700 Subject: [PATCH 1/3] [EuiProviders] Warn Developer if EuiProvider is missing --- .../src/chrome_service.tsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx b/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx index 380314554dedda..c9adcedd34c704 100644 --- a/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx +++ b/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx @@ -11,6 +11,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { BehaviorSubject, combineLatest, merge, type Observable, of, ReplaySubject } from 'rxjs'; import { mergeMap, map, takeUntil, filter } from 'rxjs'; import { parse } from 'url'; +import { setEuiDevProviderWarning } from '@elastic/eui'; import useObservable from 'react-use/lib/useObservable'; import type { CoreContext } from '@kbn/core-base-browser-internal'; @@ -189,6 +190,37 @@ export class ChromeService { this.initVisibility(application); this.handleEuiFullScreenChanges(); + // Ensure developers are notified if working in a context that lacks the EUI Provider. + const isDev = this.params.coreContext.env.mode.name === 'development'; + if (isDev) { + setEuiDevProviderWarning((providerError) => { + const errorObject = new Error(providerError.toString()); + // show a stack trace in the console + // eslint-disable-next-line no-console + console.error(errorObject); + + notifications.toasts.addDanger({ + title: '`EuiProvider` is missing', + text: mountReactNode( +

+ + https://docs.elastic.dev/kibana-dev-docs/react-context + + ), + }} + /> +

+ ), + toastLifeTimeMs: 60 * 60 * 1000, // keep message visible for up to an hour + }); + }); + } + const globalHelpExtensionMenuLinks$ = new BehaviorSubject( [] ); From 535fe00de1e1323f844ba6de437e83cb2e16e506 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 22 Jul 2024 07:48:32 -0700 Subject: [PATCH 2/3] add data-test-subj for functional test support --- .../chrome/core-chrome-browser-internal/src/chrome_service.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx b/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx index c9adcedd34c704..b46f220aa0bc6f 100644 --- a/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx +++ b/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx @@ -202,7 +202,7 @@ export class ChromeService { notifications.toasts.addDanger({ title: '`EuiProvider` is missing', text: mountReactNode( -

+

Date: Tue, 23 Jul 2024 11:15:52 -0700 Subject: [PATCH 3/3] helper method --- .../src/chrome_service.tsx | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx b/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx index b46f220aa0bc6f..5f9a17713861cb 100644 --- a/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx +++ b/packages/core/chrome/core-chrome-browser-internal/src/chrome_service.tsx @@ -174,23 +174,8 @@ export class ChromeService { this.mutationObserver.observe(body, { attributes: true }); }; - public setup({ analytics }: SetupDeps) { - const docTitle = this.docTitle.setup({ document: window.document }); - registerAnalyticsContextProvider(analytics, docTitle.title$); - } - - public async start({ - application, - docLinks, - http, - injectedMetadata, - notifications, - customBranding, - }: StartDeps): Promise { - this.initVisibility(application); - this.handleEuiFullScreenChanges(); - - // Ensure developers are notified if working in a context that lacks the EUI Provider. + // Ensure developers are notified if working in a context that lacks the EUI Provider. + private handleEuiDevProviderWarning = (notifications: NotificationsStart) => { const isDev = this.params.coreContext.env.mode.name === 'development'; if (isDev) { setEuiDevProviderWarning((providerError) => { @@ -220,6 +205,24 @@ export class ChromeService { }); }); } + }; + + public setup({ analytics }: SetupDeps) { + const docTitle = this.docTitle.setup({ document: window.document }); + registerAnalyticsContextProvider(analytics, docTitle.title$); + } + + public async start({ + application, + docLinks, + http, + injectedMetadata, + notifications, + customBranding, + }: StartDeps): Promise { + this.initVisibility(application); + this.handleEuiFullScreenChanges(); + this.handleEuiDevProviderWarning(notifications); const globalHelpExtensionMenuLinks$ = new BehaviorSubject( []