Skip to content

perf(dashboard): lazy-load recharts via next/dynamic to trim dashboard route JS #220

Closed

Description

@gkhngyk

What

7 client components statically import recharts, so the library (heavy — it pulls in several d3-* packages) is eagerly bundled into the client JS of every dashboard route that uses a chart. Loading it via next/dynamic instead defers it until the chart actually renders, shrinking the initial JS for those routes and improving hydration / time-to-interactive.

Note on scope: the Next.js App Router code-splits per route, so recharts is not in the global app bundle — it only weighs down the dashboard routes that render charts (the marketing/auth pages are unaffected). The win is per-route, not app-wide.

Files that statically import recharts

  • web/src/app/[locale]/(dashboard)/dashboard/insights/_charts.tsx
  • web/src/app/[locale]/(dashboard)/dashboard/traffic/_charts.tsx
  • web/src/app/[locale]/(dashboard)/dashboard/prompts/_charts.tsx
  • web/src/app/[locale]/(dashboard)/dashboard/shopping/page.tsx
  • web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx
  • web/src/app/[locale]/(dashboard)/dashboard/topics/[id]/page.tsx
  • web/src/components/agent/agent-chart.tsx

All are 'use client' components; none are currently lazy-loaded.

Suggested approach

Load each chart component through next/dynamic with ssr: false and a lightweight skeleton fallback. Charts are client-only visualizations behind auth, so disabling SSR costs nothing (no SEO/content impact) and keeps recharts out of the route's first paint.

For the dedicated chart files (*_charts.tsx, agent-chart.tsx), wrap them at the import site:

import dynamic from 'next/dynamic';
import { Skeleton } from '@/components/ui/skeleton';

const ReferralTrendChart = dynamic(
  () => import('./_charts').then((m) => m.ReferralTrendChart),
  { ssr: false, loading: () => <Skeleton className="h-64 w-full" /> },
);

For the three pages that import recharts directly (shopping, citations, topics/[id]), extract the chart JSX into a small child component first, then dynamic-import that child the same way.

Acceptance

  • No route eagerly bundles recharts; each chart loads via next/dynamic (ssr: false) with a skeleton fallback
  • All existing charts still render and behave the same once loaded
  • No hydration warnings introduced
  • (Optional) Note the before/after route JS size from next build output in the PR

Notes

  • UI/perf change only; no data or API changes.

Activity

  1. added
    enhancement
    good first issue
    on Jun 10, 2026
  2. BharadwajKanneveti commented on Jun 17, 2026

    @BharadwajKanneveti
    Contributor

    Hi @gkhngyk can I work on this issue?

  3. gkhngyk commented on Jun 18, 2026

    @gkhngyk
    ContributorAuthor

    Assigned — thanks @BharadwajKanneveti! 🎉 Recharts is imported across a few dashboard pages (insights, traffic, the agent chart, and the newer Site Audit charts), so wrapping those chart components in next/dynamic with ssr: false should trim the shared route JS nicely. Watch for layout shift — a sized placeholder/skeleton while the chart chunk loads keeps it smooth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions