graphql-js icon indicating copy to clipboard operation
graphql-js copied to clipboard

fix(jsutils): use optional chaining to prevent crash in browser

Open michaelbirchler opened this issue 1 year ago • 2 comments

Context

We use contentful/live-preview. The library has graphql-js as a dependency.

Problem

If the DOM has an element with id="process" eg. <div id="process"></div> than the current implementation of utils/instanceOf would fail.

Current implementation:

globalThis.process != null && globalThis.process.env.NODE_ENV === 'production'

with this implementation globalThis.process will return the DOM element: image

Because globalThis.process is true, the condition globalThis.process.env.NODE_ENV === 'production' gets executed and will result with an javascript error: image

michaelbirchler avatar Feb 06 '24 10:02 michaelbirchler

CLA Not Signed

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
Latest commit 9d261946976f51fbf8ad7982cb9e5dd6e2cb7acf
Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/65c20699135707000772b88c
Deploy Preview https://deploy-preview-4017--compassionate-pike-271cb3.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Feb 06 '24 10:02 netlify[bot]