Skip to content

Commit

Permalink
fix(react-intl): support opting out of global intl context (#4118) (#…
Browse files Browse the repository at this point in the history
…4125)

Co-authored-by: Raice Hannay <raice.hannay@xero.com>
  • Loading branch information
voodoocreation and Raice Hannay committed Jun 6, 2023
1 parent c1172b2 commit 357c861
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/react-intl/src/components/injectIntl.tsx
Expand Up @@ -9,14 +9,19 @@ function getDisplayName(Component: React.ComponentType<any>): string {

declare global {
interface Window {
/**
* Set this to `true` prior to mounting to bypass using a globally-exposed context.
*/
__REACT_INTL_BYPASS_GLOBAL_CONTEXT__: boolean | undefined

__REACT_INTL_CONTEXT__: React.Context<IntlShape> | undefined
}
}

// This is primarily dealing with packaging systems where multiple copies of react-intl
// might exist
const IntlContext =
typeof window !== 'undefined'
typeof window !== 'undefined' && !window.__REACT_INTL_BYPASS_GLOBAL_CONTEXT__
? window.__REACT_INTL_CONTEXT__ ||
(window.__REACT_INTL_CONTEXT__ = React.createContext<IntlShape>(
null as any
Expand Down

0 comments on commit 357c861

Please sign in to comment.