fix: Prevent undefined rendering in reasoning translations

Fixed React error #306 (text content mismatch) caused by undefined values
in reasoning translations.

Root cause: Translation functions could return undefined when:
- Translation key doesn't exist
- reasoning_data has unexpected structure
- parameters are missing

Changes:
- Added defaultValue to all translation calls
- Added || fallback operators to ensure strings are always returned
- Added proper null/undefined checks with empty string fallbacks
- Enhanced getInsightDescription with multiple fallback levels

This ensures all translation functions return valid strings, preventing
React hydration mismatches and rendering errors on the dashboard.
This commit is contained in:
Claude
2025-11-07 20:02:53 +00:00
parent e67a83ceb0
commit 027c539768
2 changed files with 25 additions and 12 deletions

View File

@@ -137,13 +137,18 @@ const AIInsightsPage: React.FC = () => {
}
try {
return t(`${category}.${insight.reasoning_data.type}`, insight.reasoning_data.parameters);
const params = {
...insight.reasoning_data.parameters,
defaultValue: insight.description || `${category}: ${insight.reasoning_data.type}`
};
const translated = t(`${category}.${insight.reasoning_data.type}`, params);
return translated || insight.description || `AI Insight: ${insight.reasoning_data.type}`;
} catch (e) {
// Fall back to description if translation key not found
return insight.description;
return insight.description || 'AI Insight';
}
}
return insight.description;
return insight.description || 'AI Insight';
};
return (