Stats: prevent _.merge from crashing reducer. #10326
Merged
+7
−2
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.
Fixes #9529
Today @jblz did some troubleshooting with his local state tree that was causing calypso to crash in Chrome. At the end of the troubleshooting, he discovered the issue to be caused by a massive array in the
statsStreak
data that was persisted inindexDB
.A screen grab of the malformed data in Jeff's persisted state tree:
Steps to Recreate
With the ability to reproduce the bug locally, I was able to find the crash was happening when
_.merge
is called against the persisted statsStreak data, and the latest data from the API.This
_.merge
crashes the browser tab, and subsequently, the "bad" data is still inindexDb
. Additionally, the query params forstatsStreak
data do not change but once per year, as the dates are based upon the calendar year... as such this problem will continually happen until the calypsoindexDB
is purged manually, or if the persisted data is too old.The question still remains of how did this malformed array get created in the first place. @jblz tested the api response via the developer console, and in other browsers/incognito tabs and we could not re-create the massive array. I plan on investigating a bit more on the API side of things to see if I can reproduce the issue there.
The solution in this PR is to create a clone of the existing
stats.list.items
state tree, and_.unset
the existing value before calling_.merge
. I'm open to other suggestions so feel free to comment with other ideas!To Test
Repeat the steps above locally, and verify the browser tab no longer crashes when using this branch.