-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[context] Unify Contexts, deprecate others (#161914)
> Pre-req for #56406 ## Summary We've had a long-standing problem in Kibana around our use of React context, particularly with EUI and i18n. There hasn't existed an idempotent context structure, and that has lead to a lot of unexpected results, (e.g. missing translations, inconsistent dark mode, excess context providers, etc). The biggest change coming from this PR is knowing exactly which provider to use in a particular use case. This means, for example, `ReactDOM.render` calls won't be missing `i18n` or `theme` due to a missing context. It also allows consumers to use `darkMode` without having to read the `uiSetting` themselves, instead allowing the context to do it for them. We also haven't been honoring the intended [`EuiProvider` API](https://eui.elastic.co/#/utilities/provider#theming-and-global-styles)... in some cases we've been creating and re-creating the Emotion caches, often by copy/paste of the cache code. We've also been nesting `EuiThemeProvider` contexts unnecessarily-- thinking we need to render a theme provider in an isolated component-- which renders an additional `span` element into the DOM. This PR attempts to address this inconsistency by creating a set of context providers divided by use case: ![diagram](https://github.com/elastic/kibana/assets/297604/e01c6296-1b7a-4639-ae96-946866950efe) ### `KibanaRootContextProvider` A root context provider for Kibana. This is the top level context provider that wraps the entire application. It is responsible for initializing all of the other contexts and providing them to the application. It's provided as a package for specific use cases, (e.g. the `RenderingService`, cases where we replace the entire page content, Storybook, testing, etc), but not intended for plugins. ### `KibanaRenderContextProvider` A render context provider for Kibana. This context is designed to be used with ad-hoc renders of React components, (usually with `ReactDOM.render`). ### `KibanaThemeContextProvider` A theme context provider for Kibana. A corollary to EUI's `EuiThemeProvider`, it uses Kibana services to ensure the EUI Theme is customized correctly. ### (deprecated) `KibanaStyledComponentsThemeProvider` A styled components theme provider for Kibana. This package is supplied for compatibility with legacy code, but should not be used in new code. ## Deprecation strategy This PR does *not* change any use of context by consumers. It maps the existing contexts in `kibanaReact` to the new contexts, (along with the loose API). This means that we won't have completely fixed all of our dark mode issues yet. But this is necessary to keep this PR focused on the change, rather than drawing in a lot of teams to review individual uses. We should, however, see an immediate performance improvement in the UI from the reduction in `EuiProvider` calls. ## Open questions - [ ] Does it make sense to expose a `useTheme` hook from `@kbn/react-kibana-context-theme` to replace `useEuiTheme`? ## Next steps - [ ] Update deprecated uses to new contexts. - [ ] Audit and update calls to `ReactDOM.render`. - [ ] Add ESLint rule to warn for use of EUI contexts. - [ ] Delete code from `kibanaReact`.
- Loading branch information
1 parent
0ecc28b
commit 477505a
Showing
112 changed files
with
2,095 additions
and
1,322 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...rs/core-fatal-errors-browser-internal/src/__snapshots__/fatal_errors_service.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...core-notifications-browser-internal/src/toasts/__snapshots__/toasts_service.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.