Fix bug when fetching user metrics for dashboard header (fixes #2409) #2411
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.
There were a couple of bugs in
WithUserMetrics.componentDidUpdate
that prevented it from running when it was supposed to. When the component mounts,props.user
is null. Once the user loads,componentDidUpdate
is supposed to fetch leaderboard metrics, but since it first checks ifprevProps["user"]?.score
is truthy, it was doing nothing. This only triggered during full page load; when navigating from another routecomponentDidMount
would run with a non-nulluser
and correctly fetch the metrics. The problem condition wasn't necessary during either mount or update, so I removed it. I also made the update methods async, removed unused arguments, and fixed a bug where{ loading: true }
would be set if the user had opted out of leaderboards (resulting I think in a spinner being shown forever, though I didn't test to verify this).