Skip to content

fix: prevent GraphViewTimeline from mutating shared commits array#126

Merged
NiklasSkulll merged 8 commits into
devfrom
60-general-refactoring-umbrella-issue
Apr 8, 2026
Merged

fix: prevent GraphViewTimeline from mutating shared commits array#126
NiklasSkulll merged 8 commits into
devfrom
60-general-refactoring-umbrella-issue

Conversation

@jonasyr
Copy link
Copy Markdown
Owner

@jonasyr jonasyr commented Apr 7, 2026

Summary

Bug fixes

  • ActivityChart: bucket commits by local date instead of UTC — commits near midnight were assigned to the wrong day for users in non-UTC timezones (toISOString()getFullYear/getMonth/getDate)
  • GraphViewTimeline: stop mutating shared commits prop array — processCommits was calling .sort() directly on the prop, causing cross-tab ordering side effects for other dashboard views

Code quality (SonarCloud)

  • ActivityChart: extract inline Tooltip render fn to ActivityChartTooltip component; optional chain payload?.length; Readonly<ActivityChartProps>
  • GraphViewTimeline: extract pluralize() helper to fix 5 negated-condition findings and reduce formatRelativeTime cognitive complexity below threshold; Readonly<GraphViewTimelineProps>; stable key props (branch.name, event.hash); extract eventsToShow variable to eliminate nested ternary in JSX

Infrastructure

  • Pin lodash to ^4.17.21 via pnpm.overrides to resolve Snyk CVEs (transitive deps declared wide version ranges)
  • Exclude node_modules/** from SonarCloud source scan

Test plan

  • pnpm test — 996 tests pass
  • ActivityChart.test.tsx — 4 tests including local-date bucketing case
  • GraphViewTimeline.test.tsx — 3 tests: happy path, no-mutation assertion, limit enforcement

🤖 Generated with Claude Code

jonasyr and others added 8 commits April 7, 2026 18:04
  toISOString() always returns UTC, so commits near midnight were
  assigned to the wrong day for users in non-UTC timezones. Replace
  with getFullYear/getMonth/getDate to use the browser's local date.

  Adds unit tests for ActivityChart and a global ResizeObserver mock
  in test-setup.ts to support Recharts under jsdom.
processCommits called .sort() directly on the commits prop, mutating
the shared array in place and causing cross-tab ordering side effects.
Spread to a copy before sorting ([...commits].sort(...)).

Adds GraphViewTimeline unit tests (happy path, no-mutation, limit)
and strengthens ActivityChart tests with a local-date bucketing case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…sitive lodash CVEs

lodash 4.17.21 (the patched version) is already installed. SonarCloud was
flagging prototype-pollution and code-injection CVEs because sonar.sources=.
caused it to walk node_modules and resolve transitive dependency ranges that
include vulnerable versions. Adding node_modules/** to sonar.exclusions
removes the false positives without affecting source analysis.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Snyk flagged prototype-pollution and code-injection vulnerabilities in
lodash via transitive dependencies (recharts etc.) that declare wide
version ranges. Adding a pnpm override forces the resolved version to
4.17.21 which contains all known fixes, making the Snyk findings go away.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…meline

ActivityChart:
- Extract inline Tooltip render function to ActivityChartTooltip component
- Use optional chain (payload?.length) instead of explicit null check
- Mark ActivityChartProps as Readonly

GraphViewTimeline:
- Extract pluralize() helper to eliminate 5 negated-condition findings
  and reduce cognitive complexity of formatRelativeTime below threshold
- Mark GraphViewTimelineProps as Readonly
- Replace array index keys with stable keys (branch.name, event.hash)
- Extract eventsToShow variable to eliminate nested ternary in JSX

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ld error

The extracted tooltip component used a hand-written props type that was
incompatible with Recharts' ContentType<ValueType, NameType>. Switch to
the official TooltipProps generic to satisfy the overload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds coverage for CodeChurnChart, FileDistributionChart, Footer, Header,
InfoModal, LandingPage, LoadingSpinner, NewsDrawer, RiveLoader, RiveLogo,
and SettingsDrawer following the AAA pattern.
…ne branches

ActivityChart:
- Export ActivityChartTooltip to enable direct unit testing
- Test tooltip renders date and commit count when active (happy path)
- Test tooltip renders nothing when inactive

GraphViewTimeline:
- Test fallback timeline events rendered when no commits provided
- Test singular time unit (1 day ago) via formatRelativeTime/pluralize
- Test locale date fallback for commits older than 12 months
- Test Show More button reveals additional commits beyond default 5

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 8, 2026

@jonasyr jonasyr requested a review from NiklasSkulll April 8, 2026 12:04
@NiklasSkulll NiklasSkulll merged commit 12efe61 into dev Apr 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants