launchdarkly / react-client-sdk

LaunchDarkly Client-side SDK for React.js
Other
79 stars 67 forks source link

Launch darkly version 3+ crashes older browsers #182

Closed gregdolby closed 1 year ago

gregdolby commented 1 year ago

Describe the bug Launch darkly version 3+ crashes chrome browser's version 79 or lower. I noticed this when trying to run a web app on Samsung Tizen TV because they use older browsers. Then I was able to reproduce in an older version of Chrome using BrowserStack

To reproduce Load an app on chrome browser 79 or lower (I used browserstack)

Expected behavior I expect it to load properly on older browsers

Logs

Screen Shot 2023-02-01 at 2 07 07 PM

SDK version 3.1.0

Language version, developer tools Node v16.8.0 npm 7.21.0

OS/platform chrome 79 macOS Monterey 12.6.3

yusinto commented 1 year ago

The React SDK v3.0 and up uses optional chaining which is supported by modern browsers. It looks like you bundle your react app using webpack. The issue is webpack 4 uses a version of acorn which does not transpile the optional chaining operator. The solution as you can see in the react async provider example is to resolve the acorn package version that does support it. To do this, in your package.json file:

  "resolutions": {
    "acorn": "npm:acorn-with-stage3"
  }

Webpack 5 supports optional chaining out of the box so we recommend you upgrade to that if possible. If you use other bundlers, make sure to enable/include plugins for optional chaining for your bundler.

yauheniivashkevich commented 1 year ago

I have the same issue when run jest test adding resolutions don't help to fix that

yusinto commented 1 year ago

This should be fixed in 3.0.2. We have removed the optional chaining operator so please update to that version if you have issues with the ? operator.