From 58f0d04c103b0e2500a6a927087b006b2537f663 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 20 Nov 2019 18:57:50 +0100 Subject: [PATCH] [core] Add displayName to contexts (#18468) --- docs/src/modules/components/PageContext.js | 4 ++++ docs/src/modules/components/ThemeContext.js | 6 +++++- packages/material-ui-lab/src/TreeView/TreeViewContext.js | 8 +++++++- .../src/StylesProvider/StylesProvider.js | 4 ++++ packages/material-ui-styles/src/useTheme/ThemeContext.js | 4 ++++ .../src/ExpansionPanel/ExpansionPanelContext.js | 4 ++++ .../material-ui/src/FormControl/FormControlContext.js | 4 ++++ packages/material-ui/src/List/ListContext.js | 4 ++++ packages/material-ui/src/RadioGroup/RadioGroupContext.js | 4 ++++ packages/material-ui/src/Table/TableContext.js | 4 ++++ packages/material-ui/src/Table/Tablelvl2Context.js | 4 ++++ packages/material-ui/src/test-utils/RenderMode.js | 4 ++++ 12 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/src/modules/components/PageContext.js b/docs/src/modules/components/PageContext.js index 408a76ba983fe6..be0eefdcf3656d 100644 --- a/docs/src/modules/components/PageContext.js +++ b/docs/src/modules/components/PageContext.js @@ -9,4 +9,8 @@ const PageContext = React.createContext({ pages: [], }); +if (process.env.NODE_ENV !== 'production') { + PageContext.displayName = 'PageContext'; +} + export default PageContext; diff --git a/docs/src/modules/components/ThemeContext.js b/docs/src/modules/components/ThemeContext.js index 9ce32289b84bf9..3f1966c6e80399 100644 --- a/docs/src/modules/components/ThemeContext.js +++ b/docs/src/modules/components/ThemeContext.js @@ -88,9 +88,13 @@ const highDensity = { }; export const DispatchContext = React.createContext(() => { - throw new Error('Forgot to wrap component in ThemeContext.Provider'); + throw new Error('Forgot to wrap component in `ThemeProvider`'); }); +if (process.env.NODE_ENV !== 'production') { + DispatchContext.displayName = 'ThemeDispatchContext'; +} + const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect; export function ThemeProvider(props) { diff --git a/packages/material-ui-lab/src/TreeView/TreeViewContext.js b/packages/material-ui-lab/src/TreeView/TreeViewContext.js index d6eb2875df8787..5e312fc81994ca 100644 --- a/packages/material-ui-lab/src/TreeView/TreeViewContext.js +++ b/packages/material-ui-lab/src/TreeView/TreeViewContext.js @@ -3,4 +3,10 @@ import React from 'react'; /** * @ignore - internal component. */ -export default React.createContext({}); +const TreeViewContext = React.createContext({}); + +if (process.env.NODE_ENV !== 'production') { + TreeViewContext.displayName = 'TreeViewContext'; +} + +export default TreeViewContext; diff --git a/packages/material-ui-styles/src/StylesProvider/StylesProvider.js b/packages/material-ui-styles/src/StylesProvider/StylesProvider.js index d8ce724d3f43bc..062ad3dd9783d6 100644 --- a/packages/material-ui-styles/src/StylesProvider/StylesProvider.js +++ b/packages/material-ui-styles/src/StylesProvider/StylesProvider.js @@ -28,6 +28,10 @@ const defaultOptions = { export const StylesContext = React.createContext(defaultOptions); +if (process.env.NODE_ENV !== 'production') { + StylesContext.displayName = 'StylesContext'; +} + let injectFirstNode; function StylesProvider(props) { diff --git a/packages/material-ui-styles/src/useTheme/ThemeContext.js b/packages/material-ui-styles/src/useTheme/ThemeContext.js index 157bd4627f1efb..6cf21843edcd3e 100644 --- a/packages/material-ui-styles/src/useTheme/ThemeContext.js +++ b/packages/material-ui-styles/src/useTheme/ThemeContext.js @@ -2,4 +2,8 @@ import React from 'react'; const ThemeContext = React.createContext(null); +if (process.env.NODE_ENV !== 'production') { + ThemeContext.displayName = 'ThemeContext'; +} + export default ThemeContext; diff --git a/packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js b/packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js index 0b35f26976011d..2ea07f2e0ddd31 100644 --- a/packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js +++ b/packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js @@ -6,4 +6,8 @@ import React from 'react'; */ const ExpansionPanelContext = React.createContext({}); +if (process.env.NODE_ENV !== 'production') { + ExpansionPanelContext.displayName = 'ExpansionPanelContext'; +} + export default ExpansionPanelContext; diff --git a/packages/material-ui/src/FormControl/FormControlContext.js b/packages/material-ui/src/FormControl/FormControlContext.js index 7b5d78eb3aaf1e..eb6e9a8141a972 100644 --- a/packages/material-ui/src/FormControl/FormControlContext.js +++ b/packages/material-ui/src/FormControl/FormControlContext.js @@ -5,6 +5,10 @@ import React from 'react'; */ const FormControlContext = React.createContext(); +if (process.env.NODE_ENV !== 'production') { + FormControlContext.displayName = 'FormControlContext'; +} + export function useFormControl() { return React.useContext(FormControlContext); } diff --git a/packages/material-ui/src/List/ListContext.js b/packages/material-ui/src/List/ListContext.js index 6e74dad43e9390..cb4bbfe97cba2e 100644 --- a/packages/material-ui/src/List/ListContext.js +++ b/packages/material-ui/src/List/ListContext.js @@ -5,4 +5,8 @@ import React from 'react'; */ const ListContext = React.createContext({}); +if (process.env.NODE_ENV !== 'production') { + ListContext.displayName = 'ListContext'; +} + export default ListContext; diff --git a/packages/material-ui/src/RadioGroup/RadioGroupContext.js b/packages/material-ui/src/RadioGroup/RadioGroupContext.js index 22f5760984d9db..3ede455c2e18a8 100644 --- a/packages/material-ui/src/RadioGroup/RadioGroupContext.js +++ b/packages/material-ui/src/RadioGroup/RadioGroupContext.js @@ -5,4 +5,8 @@ import React from 'react'; */ const RadioGroupContext = React.createContext(); +if (process.env.NODE_ENV !== 'production') { + RadioGroupContext.displayName = 'RadioGroupContext'; +} + export default RadioGroupContext; diff --git a/packages/material-ui/src/Table/TableContext.js b/packages/material-ui/src/Table/TableContext.js index 70fd54205d7c0b..37bd6d9714c4ed 100644 --- a/packages/material-ui/src/Table/TableContext.js +++ b/packages/material-ui/src/Table/TableContext.js @@ -5,4 +5,8 @@ import React from 'react'; */ const TableContext = React.createContext(); +if (process.env.NODE_ENV !== 'production') { + TableContext.displayName = 'TableContext'; +} + export default TableContext; diff --git a/packages/material-ui/src/Table/Tablelvl2Context.js b/packages/material-ui/src/Table/Tablelvl2Context.js index 695f797292e689..322f7154265189 100644 --- a/packages/material-ui/src/Table/Tablelvl2Context.js +++ b/packages/material-ui/src/Table/Tablelvl2Context.js @@ -5,4 +5,8 @@ import React from 'react'; */ const Tablelvl2Context = React.createContext(); +if (process.env.NODE_ENV !== 'production') { + Tablelvl2Context.displayName = 'Tablelvl2Context'; +} + export default Tablelvl2Context; diff --git a/packages/material-ui/src/test-utils/RenderMode.js b/packages/material-ui/src/test-utils/RenderMode.js index 44747063b4804e..f50f2d373f9dd3 100644 --- a/packages/material-ui/src/test-utils/RenderMode.js +++ b/packages/material-ui/src/test-utils/RenderMode.js @@ -3,6 +3,10 @@ import * as PropTypes from 'prop-types'; const Context = React.createContext(); +if (process.env.NODE_ENV !== 'production') { + Context.displayName = 'RenderContext'; +} + /** * @ignore - internal component. */