[Core Rendering Service] Mark KibanaRenderContextProvider as deprecated (#219313)

## Summary

Set `KibanaRenderContextProvider` as deprecated and comment that
consumers should use `core.rendering.addContext` instead.

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Christiane (Tina) Heiligers <christiane.heiligers@elastic.co>
This commit is contained in:
Tim Sullivan 2025-04-29 17:14:28 -07:00 committed by GitHub
parent f13c764115
commit f2461b9b6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 66 additions and 53 deletions

View file

@ -77,7 +77,7 @@ Even if you are very careful, the more UI automation you do the more likely you
## Incorrect usage of EUI components in React code will cause a functional test failure ## Incorrect usage of EUI components in React code will cause a functional test failure
For EUI to support theming and internationalization, EUI components in your React application must be wrapped in `EuiProvider` (more preferably, use the `KibanaRenderContextProvider` wrapper). The functional test runner treats EUI as a first-class citizen and will throw an error when incorrect usage of EUI is detected. However, experiencing this type of failure in a test run is unlikely: in dev mode, a toast message alerts developers of incorrect EUI usage in real-time. For EUI to support theming and internationalization, EUI components in your React application must be wrapped in `EuiProvider` (more preferably, use the <DocLink id="kibDevRenderingService" text="`core.rendering.addContext()`"/>) wrapper. The functional test runner treats EUI as a first-class citizen and will throw an error when incorrect usage of EUI is detected. However, experiencing this type of failure in a test run is unlikely: in dev mode, a toast message alerts developers of incorrect EUI usage in real-time.
## Do you really need a functional test for this? ## Do you really need a functional test for this?

View file

@ -1,7 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders matching snapshot 1`] = ` exports[`renders matching snapshot 1`] = `
<Fragment> <I18nProvider>
<EuiProvider>
<p <p
data-test-subj="errorToastMessage" data-test-subj="errorToastMessage"
> >
@ -22,5 +23,6 @@ exports[`renders matching snapshot 1`] = `
/> />
</EuiButton> </EuiButton>
</div> </div>
</Fragment> </EuiProvider>
</I18nProvider>
`; `;

View file

@ -3,6 +3,8 @@
exports[`#start() renders the GlobalToastList into the targetDomElement param 1`] = ` exports[`#start() renders the GlobalToastList into the targetDomElement param 1`] = `
Array [ Array [
Array [ Array [
<I18nProvider>
<EuiProvider>
<GlobalToastList <GlobalToastList
dismissToast={[Function]} dismissToast={[Function]}
reportEvent={ reportEvent={
@ -27,7 +29,9 @@ Array [
}, },
} }
} }
/>, />
</EuiProvider>
</I18nProvider>,
<div <div
test="target-dom-element" test="target-dom-element"
/>, />,

View file

@ -7,7 +7,10 @@
* License v3.0 only", or the "Server Side Public License, v 1". * License v3.0 only", or the "Server Side Public License, v 1".
*/ */
import React from 'react';
import type { RenderingService } from '@kbn/core-rendering-browser'; import type { RenderingService } from '@kbn/core-rendering-browser';
import { EuiProvider } from '@elastic/eui';
import { I18nProvider } from '@kbn/i18n-react';
/** /**
* This is declared internally to avoid a circular dependency issue * This is declared internally to avoid a circular dependency issue
@ -27,7 +30,11 @@ const createMockInternal = () => {
const createMock = () => { const createMock = () => {
const mocked: jest.Mocked<RenderingService> = { const mocked: jest.Mocked<RenderingService> = {
addContext: jest.fn().mockImplementation((element) => element), addContext: jest.fn().mockImplementation((element) => (
<I18nProvider>
<EuiProvider>{element}</EuiProvider>
</I18nProvider>
)),
}; };
return mocked; return mocked;
}; };

View file

@ -12,7 +12,8 @@
"**/*.tsx" "**/*.tsx"
], ],
"kbn_references": [ "kbn_references": [
"@kbn/core-rendering-browser" "@kbn/core-rendering-browser",
"@kbn/i18n-react"
], ],
"exclude": [ "exclude": [
"target/**/*" "target/**/*"

View file

@ -21,7 +21,9 @@ export type KibanaRenderContextProviderProps = Omit<KibanaRootContextProviderPro
/** /**
* The `KibanaRenderContextProvider` provides the necessary context for an out-of-current React render, such as using `ReactDOM.render()`. * The `KibanaRenderContextProvider` provides the necessary context for an out-of-current React render, such as using `ReactDOM.render()`.
* *
/**
* @internal Use RenderingService.addContext from the CoreStart contract instead of consuming this directly. * @internal Use RenderingService.addContext from the CoreStart contract instead of consuming this directly.
* @deprecated
*/ */
export const KibanaRenderContextProvider: FC< export const KibanaRenderContextProvider: FC<
PropsWithChildren<KibanaRenderContextProviderProps> PropsWithChildren<KibanaRenderContextProviderProps>

View file

@ -21,7 +21,6 @@ import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks'
import { IndexPattern } from '../../types'; import { IndexPattern } from '../../types';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import { documentField } from '../form_based/document_field'; import { documentField } from '../form_based/document_field';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
jest.mock('@kbn/unified-field-list/src/services/field_stats', () => ({ jest.mock('@kbn/unified-field-list/src/services/field_stats', () => ({
loadFieldStats: jest.fn().mockResolvedValue({}), loadFieldStats: jest.fn().mockResolvedValue({}),
@ -156,13 +155,11 @@ describe('Lens Field Item', () => {
const Wrapper: React.FC<{ const Wrapper: React.FC<{
children: React.ReactNode; children: React.ReactNode;
}> = ({ children }) => { }> = ({ children }) => {
return ( return mockedServices.core.rendering.addContext(
<KibanaRenderContextProvider {...mockedServices.core}>
<KibanaContextProvider services={mockedServices}> <KibanaContextProvider services={mockedServices}>
<button>close the euiPopover</button> <button>close the euiPopover</button>
{children} {children}
</KibanaContextProvider> </KibanaContextProvider>
</KibanaRenderContextProvider>
); );
}; };
@ -396,11 +393,11 @@ describe('Lens Field Item', () => {
}; };
render( render(
<KibanaRenderContextProvider {...mockedServices.core}> mockedServices.core.rendering.addContext(
<KibanaContextProvider services={services}> <KibanaContextProvider services={services}>
<InnerFieldItem {...defaultProps} /> <InnerFieldItem {...defaultProps} />
</KibanaContextProvider> </KibanaContextProvider>
</KibanaRenderContextProvider> )
); );
await waitFor(() => { await waitFor(() => {
expect(screen.getByTestId('field-bytes-showDetails')).toBeInTheDocument(); expect(screen.getByTestId('field-bytes-showDetails')).toBeInTheDocument();