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

instanceOf: disable dev instanceOf checks if NODE_ENV not set #4188

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yaacovCR
Copy link
Contributor

@yaacovCR yaacovCR commented Sep 9, 2024

development behavior should be opt in, not opt out

#4075 (comment)

@yaacovCR yaacovCR requested a review from a team as a code owner September 9, 2024 11:56
Copy link

netlify bot commented Sep 9, 2024

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 079409e
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/66e006b02d79130008425d38
😎 Deploy Preview https://deploy-preview-4188--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.

Copy link

github-actions bot commented Sep 9, 2024

Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

@yaacovCR yaacovCR added the PR: breaking change 💥 implementation requires increase of "major" version number label Sep 9, 2024
@yaacovCR yaacovCR force-pushed the switch-default branch 3 times, most recently from 903f7b6 to a20454f Compare September 9, 2024 12:24
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Sep 9, 2024

This will still not fix #4017. An alternative to this PR would be to rearchitect the instanceOf checks more completely....

@JoviDeCroock @phryneas @benjie

@JoviDeCroock
Copy link
Member

@yaacovCR yes as proposed in graphql/graphql-js-wg#125

JoviDeCroock
JoviDeCroock previously approved these changes Sep 9, 2024
Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think defaulting to production mode makes sense; however it will probably cause more issues to be filed to be aware of that.

globalThis.process != null &&
// eslint-disable-next-line no-undef
process.env.NODE_ENV === 'production';
process.env.NODE_ENV === 'development';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test and development should both invoke the non-production behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To minimize the size of this PR, I'd personally rewrite this to just:

const isProduction = process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test';

Then the lower lines in this PR shouldn't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9654570

so this is now:

const isProduction = globalThis.process == null || (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test');

retaining the check to see whether process is defined globally

Copy link
Contributor Author

@yaacovCR yaacovCR Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JoviDeCroock/graphql-minifier-experiments#1

I have not gone through all the bundlers, but I think that flipping the default would require us changing our instructions about what to set globalThis.process to, now we would have to set to null

https://github.com/graphql/graphql-js/blob/16.x.x/website/docs/tutorials/going-to-production.md

and if I remember correctly, the reason that is in at all is to support cloudflare.

So I am not sure if I want to move forward with this PR actually.... as if we have a better long-term solution, we should move to that without this intermediate stage......?

@JoviDeCroock @benjie @phryneas

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long-term solution: 3 versions of this file - one with the development export condition, without any of this logic, one with the production export condition without any of this, and one default that falls back to this (or a similar) solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phryneas I closed #4221 because once we use an imports map, it becomes tricky to use graphql in browsers in a bundler-free manner. I think unfortunately using the exports map and publishing instanceOf might have the same problem.

Copy link

@phryneas phryneas Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaacovCR What problems are you seeing?
Generally, I'd say that unless we publish only a single file, users will have to adopt import maps, but that's the future of ESM on the web anyways.

PS: see https://github.com/apollographql/apollo-client/blob/main/integration-tests/browser-esm/html/jspm-prepared.html for an example

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(That said, if we were to continue with #4221, we would need to ship a rolled-up browser entry point that didn't reference imports - maybe with a separate development and production build.
To be honest, I don't really think we'd need sub-entrypoint browser builds, people who run without a bundler probably don't care about saving bundlesize anyways.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure if we want to require the use of an import map but I would definitely defer to @JoviDeCroock on that.

Copy link
Member

@JoviDeCroock JoviDeCroock Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phryneas Import maps are still being adopted and imho aren't in a well enough state yet for a reference implementation based on a standard to adopt nor is the spec far along enough for it. My two cents here being that either we remove instanceof all together and replace it with a branded symbol/types only approach or we keep the status quo but default to production instead.

package.json Show resolved Hide resolved
Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t like adding a dependency just to set an envvar; but 🤷‍♂️

It seems possible for globalThis.process to exist without globalThis.process.env, which would cause a throw. But that’s an issue with the existing code anyway.

Looks alright; I can’t comment whether it impacts bundling/tree-shaking.

@yaacovCR yaacovCR mentioned this pull request Sep 27, 2024
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: breaking change 💥 implementation requires increase of "major" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants