fix error when removing items from storage from a second tab #55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey Countly Team, thanks for making this great product.
I have noticed a bug in my application with the Countly library, steps to reproduce:
Description of Issue and Steps to Reproduce
localStorage
on one of the tabs, likelocalStorage.removeItem('cly_event')
cannot read property 'length' of null
Root Cause of Issue
I traced this down to a line in the Countly SDK:
I noticed that another section of the Countly SDK listens to changes on
localStorage
, and tries to update them when they change:So, for example, if we call
localStorage.removeItem('cly_event')
, the above code will be run and the new value ofeventQueue
will benull
.Then, when
eventQueue.length
is called, an error will be thrown.I discovered the issue when running Cypress tests. Cypress clears lots of state-ish things between tests, and sometimes it does that just after the application has loaded, causing this error.
From reading the code, it seems to me like you never really want these values to be
null
, even if they arenull
inlocalStorage
.What do you think of this PR? Also, if this can be merged, how can I get the change into the minified file? Are there any tests you need written?
Thanks!