Skip to content

fix: crash on mobile caused by ChartTooltipContent outside ChartContainer#54

Merged
lukekarrys merged 1 commit intovltpkg:mainfrom
vltbaudbot:fix/benchmarks-mobile-crash
Mar 5, 2026
Merged

fix: crash on mobile caused by ChartTooltipContent outside ChartContainer#54
lukekarrys merged 1 commit intovltpkg:mainfrom
vltbaudbot:fix/benchmarks-mobile-crash

Conversation

@vltbaudbot
Copy link
Contributor

Problem

The benchmarks app crashes on mobile screens (< 768px) with the ErrorBoundary message:

Something went wrong — We're sorry, but something unexpected happened.

The same crash occurs on desktop when resizing the browser window below 768px.

Root Cause

The mobile chart code paths (introduced in #52) use <ResponsiveContainer> directly instead of <ChartContainer>. However, the tooltip inside them still used <ChartTooltipContent>, which calls useChart() — a hook that requires <ChartContainer>'s React context.

When Recharts renders the tooltip component (even when inactive), useChart() throws:

Error: useChart must be used within a <ChartContainer />

This is caught by the ErrorBoundary, showing the crash screen.

Why it only happens on mobile:

  1. useMediaQuery('(max-width: 767px)') initializes as false
  2. On small screens, useEffect fires and flips isMobile to true
  3. React re-renders into the mobile code path using ResponsiveContainer
  4. ChartTooltipContent renders → calls useChart() → throws

Fix

Added a standalone MobileTooltipContent component that provides the same tooltip UI (color indicators, DNF support, formatted values) without depending on useChart()/ChartContext. Replaced the two mobile ChartTooltip usages with Recharts' native <Tooltip> + MobileTooltipContent.

Desktop code paths continue using ChartTooltipContent inside ChartContainer unchanged.

Changes

File Change
app/src/components/variation/chart.tsx Add MobileTooltipContent, replace mobile tooltip usage

Build: ✅ tsc -b && vite build clean
Format: ✅ Prettier clean

…iner

The mobile chart code paths (introduced in vltpkg#52) use <ResponsiveContainer>
instead of <ChartContainer>, but the tooltip inside them used
<ChartTooltipContent> which calls useChart() — a hook that requires
<ChartContainer>'s context. This throws immediately when Recharts renders
the tooltip component, crashing the app on screens < 768px.

Fix: Add a standalone MobileTooltipContent component that provides the
same tooltip UI without depending on useChart()/ChartContext. The desktop
code paths continue using ChartTooltipContent inside ChartContainer as
before.
@lukekarrys lukekarrys merged commit 9af4920 into vltpkg:main Mar 5, 2026
1 check failed
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.

3 participants