Skip to content

The Open Source DocuSign Alternative.

fix: ssr hydration error in piechart

Ephraim Atta-Duncan4bfbe039e852
diff --git a/apps/marketing/src/app/(marketing)/open/cap-table.tsx b/apps/marketing/src/app/(marketing)/open/cap-table.tsx
index 5bdea46c4..b9a27235c 100644
--- a/apps/marketing/src/app/(marketing)/open/cap-table.tsx
+++ b/apps/marketing/src/app/(marketing)/open/cap-table.tsx
@@ -1,6 +1,6 @@
'use client';
-import { HTMLAttributes } from 'react';
+import { HTMLAttributes, useEffect, useState } from 'react';
import { Cell, Pie, PieChart, Tooltip } from 'recharts';
@@ -41,33 +41,40 @@ const renderCustomizedLabel = ({
export type CapTableProps = HTMLAttributes<HTMLDivElement>;
export const CapTable = ({ className, ...props }: CapTableProps) => {
+ const [isSSR, setIsSSR] = useState(true);
+
+ useEffect(() => {
+ setIsSSR(false);
+ }, []);
return (
<div className={cn('flex flex-col', className)} {...props}>
<h3 className="px-4 text-lg font-semibold">Cap Table</h3>
<div className="border-border mt-2.5 flex flex-1 items-center justify-center rounded-2xl border shadow-sm hover:shadow">
- <PieChart width={400} height={400}>
- <Pie
- data={CAP_TABLE}
- cx="50%"
- cy="50%"
- labelLine={false}
- label={renderCustomizedLabel}
- outerRadius={180}
- innerRadius={100}
- fill="#8884d8"
- dataKey="percentage"
- >
- {CAP_TABLE.map((entry, index) => (
- <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
- ))}
- </Pie>
- <Tooltip
- formatter={(percent: number, name, props) => {
- return [`${percent}%`, name || props['name'] || props['payload']['name']];
- }}
- />
- </PieChart>
+ {!isSSR && (
+ <PieChart width={400} height={400}>
+ <Pie
+ data={CAP_TABLE}
+ cx="50%"
+ cy="50%"
+ labelLine={false}
+ label={renderCustomizedLabel}
+ outerRadius={180}
+ innerRadius={100}
+ fill="#8884d8"
+ dataKey="percentage"
+ >
+ {CAP_TABLE.map((entry, index) => (
+ <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
+ ))}
+ </Pie>
+ <Tooltip
+ formatter={(percent: number, name, props) => {
+ return [`${percent}%`, name || props['name'] || props['payload']['name']];
+ }}
+ />
+ </PieChart>
+ )}
</div>
</div>
);
diff --git a/apps/marketing/src/app/(marketing)/open/gh-metrics.tsx b/apps/marketing/src/app/(marketing)/open/gh-metrics.tsx
index 1e2fa453d..5c0c79716 100644
--- a/apps/marketing/src/app/(marketing)/open/gh-metrics.tsx
+++ b/apps/marketing/src/app/(marketing)/open/gh-metrics.tsx
@@ -9,6 +9,7 @@ import { cn } from '@documenso/ui/lib/utils';
import { StargazersType } from './page';
+export type MetricsDataKey = 'stars' | 'forks' | 'mergedPRs' | 'openIssues';
export type GithubMetricProps = HTMLAttributes<HTMLDivElement> & {
data: StargazersType;
metricKey: MetricsDataKey;
@@ -17,8 +18,6 @@ export type GithubMetricProps = HTMLAttributes<HTMLDivElement> & {
chartHeight?: number;
};
-export type MetricsDataKey = 'stars' | 'forks' | 'mergedPRs' | 'openIssues';
-
export const GithubMetric = ({
className,
data,
@@ -39,9 +38,9 @@ export const GithubMetric = ({
<div className={cn('flex flex-col', className)} {...props}>
<h3 className="px-4 text-lg font-semibold">{title}</h3>
- <div className="border-border mt-2.5 flex flex-1 items-center justify-center rounded-2xl border shadow-sm hover:shadow">
+ <div className="border-border mt-2.5 flex flex-1 items-center justify-center rounded-2xl border pr-2 shadow-sm hover:shadow">
<ResponsiveContainer width="100%" height={chartHeight}>
- <BarChart data={formattedData} margin={{ top: 40, right: 20 }}>
+ <BarChart data={formattedData} margin={{ top: 30, right: 20 }}>
<XAxis dataKey="month" />
<YAxis />
<Tooltip