Skip to content

Commit a69929d

Browse files
eps1lonAndarist
andauthored
Added display names to public React contexts in development builds (#2428)
* feat: Add display names to public React contexts * yarn changeset * Update .changeset/olive-zebras-pump.md Co-authored-by: Mateusz Burzyński <[email protected]>
1 parent 24557d9 commit a69929d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

.changeset/olive-zebras-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/react': patch
3+
---
4+
5+
Added display names to public React contexts in development builds. This helps to recognize them in React Developer Tools.

packages/react/src/context.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ let EmotionCacheContext: React.Context<EmotionCache | null> =
1818
: null
1919
)
2020

21+
if (process.env.NODE_ENV !== 'production') {
22+
EmotionCacheContext.displayName = 'EmotionCacheContext'
23+
}
24+
2125
export let CacheProvider = EmotionCacheContext.Provider
2226

2327
export let __unsafe_useEmotionCache =

packages/react/src/theming.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import weakMemoize from '@emotion/weak-memoize'
44
import hoistNonReactStatics from './isolated-hoist-non-react-statics-do-not-use-this-in-your-code'
55

66
export const ThemeContext = /* #__PURE__ */ React.createContext<Object>({})
7+
if (process.env.NODE_ENV !== 'production') {
8+
ThemeContext.displayName = 'EmotionThemeContext'
9+
}
710

811
export const useTheme = () => React.useContext(ThemeContext)
912

0 commit comments

Comments
 (0)