Skip to content

Commit

Permalink
Check for existence of global before usage (#3646)
Browse files Browse the repository at this point in the history
Summary:
An unchecked usage of `global` is causing failures in environments where it may not be polyfilled (see vercel/next.js#30968). This is fixed by adding a check for `global` in the same fashion [`registerEnvironmentWithDevTools.js`](https://github.com/facebook/relay/blob/87696f9cbf61739cb7474be447cf1d88e6eec0c8/packages/relay-runtime/util/registerEnvironmentWithDevTools.js#L21-L26) already does. The tests seem to still run fine after this, and the compiled code still references `global` so it should be a safe change 😄

Pull Request resolved: #3646

Reviewed By: josephsavona

Differential Revision: D32997065

Pulled By: alunyov

fbshipit-source-id: 1c3b8d0e5348b2d6b5b5c2ea56f2d903f84a8fcf
  • Loading branch information
rrdelaney authored and facebook-github-bot committed Jan 26, 2022
1 parent 436a084 commit d745bdf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/relay-runtime/store/RelayPublishQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,15 @@ type PendingUpdater = {|
+updater: StoreUpdater,
|};

const _global: typeof global | $FlowFixMe =
typeof global !== 'undefined'
? global
: typeof window !== 'undefined'
? window
: undefined;

const applyWithGuard =
global?.ErrorUtils?.applyWithGuard ??
_global?.ErrorUtils?.applyWithGuard ??
((callback, context, args, onError, name) => callback.apply(context, args));

/**
Expand Down

0 comments on commit d745bdf

Please sign in to comment.