Skip to content

Commit 66bc1eb

Browse files
committed
chore: add bundle size optimizations
1 parent 09a03a0 commit 66bc1eb

5 files changed

Lines changed: 46 additions & 173 deletions

File tree

webapp/next.config.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = { output: "standalone" };
2+
const nextConfig = {
3+
output: "standalone",
4+
experimental: {
5+
optimizePackageImports: ["lucide-react", "recharts", "date-fns"],
6+
},
7+
};
38

49
export default nextConfig;

webapp/src/app/(dashboard)/[organizationId]/page.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
"use client";
22

33
import Image from "next/image";
4+
import dynamic from "next/dynamic";
45
import { use, useEffect, useState } from "react";
56

67
import ErrorMessage from "@/components/error-message";
78
import Loader from "@/components/loader";
8-
import RadialChart from "@/components/radial-chart";
9+
import { Card, CardContent } from "@/components/ui/card";
10+
import { Skeleton } from "@/components/ui/skeleton";
11+
12+
// Lazy-load chart to keep recharts off the critical path
13+
const RadialChart = dynamic(() => import("@/components/radial-chart"), {
14+
loading: () => (
15+
<Card className="flex flex-col h-full items-center justify-center">
16+
<CardContent className="p-0">
17+
<Skeleton className="h-44 w-44 rounded-full" />
18+
</CardContent>
19+
</Card>
20+
),
21+
ssr: false,
22+
});
923
import {
1024
getEquivalentCarKm,
1125
getEquivalentCitizenPercentage,

webapp/src/components/area-chart-stacked.tsx

Lines changed: 0 additions & 90 deletions
This file was deleted.

webapp/src/components/bar-chart-multiple.tsx

Lines changed: 0 additions & 77 deletions
This file was deleted.

webapp/src/components/project-dashboard-base.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { DateRangePicker } from "@/components/date-range-picker";
2-
import EmissionsTimeSeriesChart from "@/components/emissions-time-series";
3-
import ExperimentsBarChart from "@/components/experiment-bar-chart";
4-
import RadialChart from "@/components/radial-chart";
5-
import RunsScatterChart from "@/components/runs-scatter-chart";
62
import { Separator } from "@/components/ui/separator";
73
import { getDefaultDateRange } from "@/helpers/date-utils";
84
import { ExperimentReport } from "@/types/experiment-report";
95
import { Project } from "@/types/project";
106
import { ConvertedValues, RadialChartData } from "@/types/project-dashboard";
117
import Image from "next/image";
8+
import dynamic from "next/dynamic";
129
import { ReactNode, useState } from "react";
1310
import { DateRange } from "react-day-picker";
1411
import ChartSkeleton from "./chart-skeleton";
@@ -20,6 +17,30 @@ import { useRouter } from "next/navigation";
2017
import { Table, TableBody, TableHeader } from "./ui/table";
2118
import { Experiment } from "@/types/experiment";
2219

20+
// Lazy-load chart components to keep recharts (~370kB) off the critical path
21+
const RadialChart = dynamic(() => import("@/components/radial-chart"), {
22+
loading: () => (
23+
<Card className="flex flex-col h-full items-center justify-center">
24+
<CardContent className="p-0">
25+
<Skeleton className="h-44 w-44 rounded-full" />
26+
</CardContent>
27+
</Card>
28+
),
29+
ssr: false,
30+
});
31+
const ExperimentsBarChart = dynamic(
32+
() => import("@/components/experiment-bar-chart"),
33+
{ loading: () => <ChartSkeleton height={300} />, ssr: false },
34+
);
35+
const RunsScatterChart = dynamic(
36+
() => import("@/components/runs-scatter-chart"),
37+
{ loading: () => <ChartSkeleton height={300} />, ssr: false },
38+
);
39+
const EmissionsTimeSeriesChart = dynamic(
40+
() => import("@/components/emissions-time-series"),
41+
{ loading: () => <ChartSkeleton height={350} />, ssr: false },
42+
);
43+
2344
export interface ProjectDashboardBaseProps {
2445
isPublicView: boolean;
2546
project: Project;

0 commit comments

Comments
 (0)