From dc27044dabe9013828b3edefa2b6debbfc1e86b0 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 11 Jan 2026 20:37:32 -0800 Subject: [PATCH] =?UTF-8?q?fix(mining-admin-web):=20=E4=BF=AE=E5=A4=8D=20f?= =?UTF-8?q?ormatNumber=20=E5=AF=BC=E8=87=B4=E7=9A=84=20hydration=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 toLocaleString 替换为确定性格式化方法,避免服务器和客户端 输出不一致导致的 React hydration 错误 #418 #423 Co-Authored-By: Claude Opus 4.5 --- frontend/mining-admin-web/src/lib/utils/format.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/mining-admin-web/src/lib/utils/format.ts b/frontend/mining-admin-web/src/lib/utils/format.ts index d2040ed9..9be81417 100644 --- a/frontend/mining-admin-web/src/lib/utils/format.ts +++ b/frontend/mining-admin-web/src/lib/utils/format.ts @@ -4,7 +4,11 @@ export function formatNumber(value: number | string | undefined | null, decimals if (value === undefined || value === null) return '-'; const num = typeof value === 'string' ? parseFloat(value) : value; if (isNaN(num)) return '-'; - return num.toLocaleString('zh-CN', { minimumFractionDigits: decimals, maximumFractionDigits: decimals }); + // 使用确定性格式化,避免 SSR hydration 错误 + const fixed = num.toFixed(decimals); + const parts = fixed.split('.'); + parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); + return parts.join('.'); } export function formatDecimal(value: string | number | undefined | null, precision = 8): string {