launchdarkly / react-client-sdk

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

null is not an object (evaluating 'window.localStorage.setItem') #109

Closed oakis closed 2 years ago

oakis commented 2 years ago

Is this a support request? Yes.

Describe the bug Haven´t seen any issues or heard of any but we get hundreds of reports from Sentry about this error.

To reproduce Seems to happen on any request to Launch Darkly.

Expected behavior Not get any reported errors.

Logs image

SDK version 2.24.0

Language version, developer tools JavaScript.

OS/platform iPad iOS 10.15.6 Safari 14.0.3

Additional context Can´t see that this is happening on Windows or in Chrome/Firefox.

kinyoklion commented 2 years ago

Hello @oakis,

Thank you for reporting this.

Just to verify, you are only seeing this on iOS and macOS?

Filed internally as 136017.

oakis commented 2 years ago

Hello @oakis,

Thank you for reporting this.

Just to verify, you are only seeing this on iOS and macOS?

Filed internally as 136017.

Yeah we are running our application in PWA mode in iPad. Have not seen this issue on a PC.

eli-darkly commented 2 years ago

Version 2.25.0 of the React SDK has been released, which should fix this. Sorry for the delay - we had fixed the underlying issue a bit earlier, which was in the JS SDK, but hadn't followed through right away to propagate the fix to React.

eli-darkly commented 2 years ago

For context: the fix is specifically in how the error is reported. "Null is not an object" in this case meant that local storage was not writable in the browser even though window.localStorage was defined— which could mean that the storage was full, or that it was disabled because the browser was in private mode; browser behavior in these cases is not really standardized, they can throw whatever error they feel like. So, the SDK won't be able to save anything in local storage, but we don't want to be logging errors about this all the time. The fix makes it so that it will just log a console message the first time it happens (that is, the first time in the lifetime of this SDK client instance, so basically once per page load) and then it assumes local storage will probably continue not working, so it won't repeatedly log errors. And there should not be any uncaught errors, which were probably what made Sentry worried.

As for whether not being able to save to local storage is really a problem or not— it depends on what you're trying to do. If you're trying to use the bootstrap: "localstorage" option in the SDK configuration, then it means you will not get the benefit of local storage caching of flag data, so that option will basically be ignored. But in this case, based on the log output, I think it was just trying to save a value to remind itself "I already sent diagnostics data to LaunchDarkly and don't need to do it again"; the result of that not working would just be that it would send some extra unnecessary diagnostics data.