Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove global in favor of globalThis for better compatibility #11976

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/server/resolve-hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Module._extensions = Object.fromEntries(

// Set __DEV__ that expo needs
// @ts-expect-error __DEV__ doesn't exist in the type definitions
global.__DEV__ = process.env.NODE_ENV !== 'production';
globalThis.__DEV__ = process.env.NODE_ENV !== 'production';

// Reanimated doesn't support SSR :(
mock(
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/src/parseErrorStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function parseErrorStack(

const parsedStack = Array.isArray(errorStack)
? errorStack
: (global as any).HermesInternal
: (globalThis as any).HermesInternal
? convertHermesStack(parseHermesStack(errorStack))
: stacktraceParser.parse(errorStack).map((frame) => ({
...frame,
Expand Down
7 changes: 4 additions & 3 deletions packages/elements/src/getNamedContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ declare global {
}

// We use a global variable to keep our contexts so that we can reuse same contexts across packages
global[contexts] = global[contexts] ?? new Map<string, React.Context<any>>();
globalThis[contexts] =
globalThis[contexts] ?? new Map<string, React.Context<any>>();

export function getNamedContext<T>(
name: string,
initialValue: T
): React.Context<T> {
let context = global[contexts].get(name);
let context = globalThis[contexts].get(name);

if (context) {
return context;
Expand All @@ -23,7 +24,7 @@ export function getNamedContext<T>(
context = React.createContext<T>(initialValue);
context.displayName = name;

global[contexts].set(name, context);
globalThis[contexts].set(name, context);

return context;
}
2 changes: 1 addition & 1 deletion packages/native/src/NavigationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare global {
>;
}

global.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
globalThis.REACT_NAVIGATION_DEVTOOLS = new WeakMap();

type Props<ParamList extends {}> = NavigationContainerProps & {
direction?: LocaleDirection;
Expand Down