-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SharedUX/React render] prevent double-nested EuiProvider #182005
Changes from 5 commits
039132d
081271e
1ecb97d
bd5a099
0ec663b
58e805b
dd3f12a
9de2153
4ce6bdc
b9029dd
773e463
ec06e0d
a0c33a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,16 @@ | |
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { I18nStart } from '@kbn/core-i18n-browser'; | ||
import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser'; | ||
import React, { FC, PropsWithChildren } from 'react'; | ||
|
||
import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser'; | ||
import type { I18nStart } from '@kbn/core-i18n-browser'; | ||
|
||
// @ts-expect-error EUI exports this component internally, but Kibana isn't picking it up its types | ||
import { useIsNestedEuiProvider } from '@elastic/eui/lib/components/provider/nested'; | ||
// @ts-expect-error EUI exports this component internally, but Kibana isn't picking it up its types | ||
import { emitEuiProviderWarning } from '@elastic/eui/lib/services/theme/warning'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we look into adding this to kbn-ui-shared-deps? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. I am looking into it now: dd3f12a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL this is an option - going to bookmark this for future reference 👀 |
||
|
||
import { KibanaEuiProvider, type KibanaEuiProviderProps } from './eui_provider'; | ||
|
||
/** Props for the KibanaRootContextProvider */ | ||
|
@@ -38,8 +44,19 @@ export const KibanaRootContextProvider: FC<PropsWithChildren<KibanaRootContextPr | |
children, | ||
i18n, | ||
...props | ||
}) => ( | ||
<KibanaEuiProvider {...props}> | ||
<i18n.Context>{children}</i18n.Context> | ||
</KibanaEuiProvider> | ||
); | ||
}) => { | ||
const hasEuiProvider = useIsNestedEuiProvider(); | ||
|
||
if (hasEuiProvider) { | ||
emitEuiProviderWarning( | ||
'KibanaRootContextProvider has likely been nested in this React tree, either by direct reference or by KibanaRenderContextProvider. The result of this nesting is a nesting of EuiProvider, which has negative effects. Check your React tree for nested Kibana context providers.' | ||
); | ||
return <i18n.Context>{children}</i18n.Context>; | ||
} else { | ||
return ( | ||
<KibanaEuiProvider {...props}> | ||
<i18n.Context>{children}</i18n.Context> | ||
</KibanaEuiProvider> | ||
); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,9 @@ import useObservable from 'react-use/lib/useObservable'; | |
|
||
import { EuiThemeProvider, EuiThemeProviderProps } from '@elastic/eui'; | ||
|
||
// @ts-ignore EUI exports this component internally, but Kibana isn't picking it up its types | ||
// @ts-expect-error EUI exports this component internally, but Kibana isn't picking it up its types | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch. |
||
import { useIsNestedEuiProvider } from '@elastic/eui/lib/components/provider/nested'; | ||
// @ts-ignore EUI exports this component internally, but Kibana isn't picking it up its types | ||
// @ts-expect-error EUI exports this component internally, but Kibana isn't picking it up its types | ||
import { emitEuiProviderWarning } from '@elastic/eui/lib/services/theme/warning'; | ||
|
||
import { KibanaEuiProvider } from '@kbn/react-kibana-context-root'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cee-chen Can this be something addressed in a future EUI release? Or is this a mistake somehow, (I don't see how).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a mistake, this has been done other places in Kibana as well (whenever devs reach into
@elastic/eui/lib
). TBH I'm not 100% sure it's solvable on just the EUI level - I think it's a weird factor of how Kibana optimizes shared dependencies and its bazel pipeline. We might need to loop in KibanaOps for this as I'm not too sure why this happens either - I do believe it used to work at some point.