fix(mining-admin-web): 修复 formatNumber 导致的 hydration 错误

将 toLocaleString 替换为确定性格式化方法,避免服务器和客户端
输出不一致导致的 React hydration 错误 #418 #423

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-11 20:37:32 -08:00
parent e0f529799f
commit dc27044dab
1 changed files with 5 additions and 1 deletions

View File

@ -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 {