Skip to content

Bug Report: In-Place Mutation of Global State in renderProgressHistoryChart #317

Description

@Yashaswini-K-P

The Issue

Inside renderProgressHistoryChart, the fallback logic calculates baseTotal by running .sort() directly on the history array. Because JavaScript arrays are passed by reference, this mutates selectedUserData.sh.history in-place within the global state cache.

The Impact

Subsequent chart updates, data re-renders, or filter toggles read a corrupted, scrambled timeline. This breaks chronological rendering, causing line plots to wildly zigzag or crash entirely.

Action Items for Maintainers

We need to determine the best path forward based on how the global state is intended to be structured:

  • Option 1 (Isolate with a Copy): If the global cache requires a strict, predictable order (e.g., newest to oldest) for other components, we should create a shallow copy ([...history].sort()) to isolate the chart's logic.
  • Option 2 (Standardize Global Order): If the array should naturally be ordered from oldest to newest across the entire app, we should move this sorting logic up to the data-fetching or state-initialization layer instead of letting a rendering function mutate it downstream.

I would like to work on this.

Metadata

Metadata

Labels

FrontendTask mainly involving frontendlevel:beginnerIndicates the difficultytype:bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions