Skip to content

Conversation

xbill82
Copy link
Contributor

@xbill82 xbill82 commented Sep 27, 2017

By injecting a BUILT constant via Webpack, and by checking the window global, we are able to detect if the user is using the Nodejs version in the browser.

@codecov-io
Copy link

codecov-io commented Sep 27, 2017

Codecov Report

Merging #249 into 5.x will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              5.x     #249   +/-   ##
=======================================
  Coverage   98.27%   98.27%           
=======================================
  Files          17       17           
  Lines        2149     2149           
  Branches      611      611           
=======================================
  Hits         2112     2112           
  Misses         37       37

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db3108f...06095cd. Read the comment docs.

@ballinette
Copy link

I suggest to be more strict and throw an error if we try to use the nodejs version in a browser

@xbill82
Copy link
Contributor Author

xbill82 commented Sep 27, 2017

@ballinette Why? Technically, the SDK works even if we use the Node version in the browser. It is a common practice in famous browser libraries like React, Redux, Vuejs, etc... To display warnings when something looks bad, but maybe the user just knows what he/she is doing.

@ballinette
Copy link

@xbill82 so I don't understand the goal here.
If the SDK works perfectly with the Node version in the brother, why should we display a warning message ?
If not, why do we allow to use it ?

Is there any acceptable use case that a browser app could use the nodejs version of the sdk instead of the built one ?

@xbill82 xbill82 changed the title Warning when using Nodejs version in browser Throw when using Nodejs version in browser Sep 28, 2017
if (typeof window !== 'undefined' && typeof BUILT === 'undefined') {
throw new Error('It looks like you are using the Nodejs version of Kuzzle SDK ' +
'in a browser. ' +
'It is strongly recommended to use the browser-specific build instead. ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we now throw an error, we are more than "strongly recommending" to use the built-version of the SDK. :-)

throw new Error('It looks like you are using the Nodejs version of Kuzzle SDK ' +
'in a browser. ' +
'It is strongly recommended to use the browser-specific build instead. ' +
'Learn more at https://github.com/kuzzleio/sdk-javascript/tree/master#browser');
Copy link
Contributor

Choose a reason for hiding this comment

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

I cannot find that anchor in our README file, either in master, 5.x or 6.x

Copy link

@ballinette ballinette Sep 28, 2017

Choose a reason for hiding this comment

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

the anchor in the README is #javascript : https://github.com/kuzzleio/sdk-javascript#javascript
should rather be #browser, imho, so the link here is correct, bug we need to fix the Readme.

Copy link
Contributor Author

@xbill82 xbill82 Oct 2, 2017

Choose a reason for hiding this comment

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

Copy link

@ballinette ballinette left a comment

Choose a reason for hiding this comment

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

OK for me, after fixing the message spotted by scottinet

@xbill82
Copy link
Contributor Author

xbill82 commented Oct 17, 2017

Merging as 4 ✅

@xbill82 xbill82 merged commit ae63475 into 5.x Oct 17, 2017
@xbill82 xbill82 deleted the browser-warning-dist branch October 17, 2017 07:39
This was referenced Oct 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants