fix(message): add robust NaN validation for date handling across components
Some checks failed
Frontend CI / build-and-push-web (push) Failing after 53s
Frontend CI / ota-android (push) Has been cancelled
Frontend CI / build-android-apk (push) Has been cancelled

Add comprehensive date validation using Number.isNaN() checks to prevent crashes when timestamps are invalid or empty. Apply defensive formatting across CommentItem, SystemMessageItem, MessageBubble, LongPressMenu, and store utilities.

Refine message bubble styling: move sender name display to both sides in group chat with distinct `mySenderName` styling, adjust bubble corner radius to top-right for consistent arrow placement, and align message rows to flex-start for improved layout. Simplify group avatar rendering in ConversationListRow.
This commit is contained in:
lafay
2026-04-25 15:25:42 +08:00
parent a6a4198ac5
commit 6b91a7ead1
14 changed files with 68 additions and 40 deletions

View File

@@ -223,8 +223,11 @@ const CommentItem: React.FC<CommentItemProps> = ({
const [isDeleting, setIsDeleting] = useState(false);
// 格式化时间
const formatTime = (dateString: string): string => {
if (!dateString) return '';
try {
return formatDistanceToNow(new Date(dateString), {
const date = new Date(dateString);
if (Number.isNaN(date.getTime())) return '';
return formatDistanceToNow(date, {
addSuffix: true,
locale: zhCN,
});

View File

@@ -331,8 +331,11 @@ const SystemMessageItem: React.FC<SystemMessageItemProps> = ({
// 格式化时间
const formatTime = (dateString: string): string => {
if (!dateString) return '';
try {
return formatDistanceToNow(new Date(dateString), {
const date = new Date(dateString);
if (Number.isNaN(date.getTime())) return '';
return formatDistanceToNow(date, {
addSuffix: true,
locale: zhCN,
});

View File

@@ -274,8 +274,11 @@ const UserProfileHeader: React.FC<UserProfileHeaderProps> = ({
<View style={styles.metaItem}>
<MaterialCommunityIcons name="calendar-outline" size={14} color={colors.text.hint} />
<Text style={styles.metaText}>
{new Date(user.created_at || Date.now()).getFullYear()}
{new Date(user.created_at || Date.now()).getMonth() + 1}
{(() => {
const d = new Date(user.created_at || Date.now());
if (Number.isNaN(d.getTime())) return '加入于 未知时间';
return `加入于 ${d.getFullYear()}${d.getMonth() + 1}`;
})()}
</Text>
</View>
</View>