-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Prevent ReferenceError when running graphql in the browser #1562
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Will |
@Neitsch would you prefer to also check for Also, what constitutes a safe change? literally anything is better than immediately throwing when trying to access |
Oops, sorry, I was thinking about something wrong. Yeah, this looks like a fine idea. Could you elaborate in which case you would not have |
Yes. I want to run this in the browser, and I don't want to solve this problem with added tooling. |
👋 Any reasons not to merge this? Here's an example use case: |
@bennypowers Sorry for delay and thanks for the ping.
Example code is missing in your comment for some reason.
Just to better understand your use case, how you handle |
whoopsie! sleep is good, I promise. sorry for the long story here but it's genuinely convoluted. https://lit-apollo-subscriptions.herokuapp.com uses
so when I handle So, I could solve this by importing builtins from
So that leaves me with the solution here: https://gitlab.com/bennyp/demo-lit-apollo-subscriptions/blob/master/src/index.html#L32 Which makes me a little sad. Why assume node-everywhere when, for the price of 44 characters of straightforward, good-old-fashioned runtime javascript, you can cover node and web cases. I hope that makes sense. |
33ce4ad
to
2664365
Compare
Not every user wants to or should use webpack to bundle graphql and related libs. Forcing web developers to cludge a global reference to an imaginary `process` in a render-blocking script is not an optimal solution, when libraries can just check it themselves.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@bennypowers Thanks for detailed explanation now its totally makes sense 👍 The ideal solution would be to find some popular library that faces the same problems and copy-paste code from here. This way we can ensure that this code is battle tested with the majority of setups/stacks without putting For example, I did a quick check for So if you have the time it would be great if you find out how other libraries solve this issue and save us from reinventing the wheel. |
in the node context this will have the exact same behavior as before It will hit the glbl = global; when it hits the The difference here is that it won't cause a ReferenceError on the web. The only danger with this approach is if someone defines proof of error (open console) |
But here are some more comprehensive thoughts on the matter |
I pushed a commit which uses the expanded In the future, I suppose |
As a hypothetical: What is the advantage of your solution over just doing `process && process.env && process.env.NODE_ENV == "production"? To use production mode you can set the global variable appropriately. On a side note, I would strongly advise declaring |
I originally did that, but a more comprehensive solution was sought |
Superseded by #2409 |
Not every user wants to or should use webpack to bundle graphql and related libs.
Forcing web developers to cludge a global reference to an imaginary
process
in a render-blocking script is not an optimal solution, when libraries can just check it themselves.