Skip to content

Commit 5d61ad7

Browse files
ggazzoclaude
andauthored
fix(useFormatDate): default Message_DateFormat to 'LL' to avoid date-fns crash (#40393)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4def392 commit 5d61ad7

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
Fixes a `date-fns` crash on routes that mount before the public settings stream finishes loading. `useFormatDate` was passing `String(undefined)` (the literal `"undefined"`) to `formatDate` while `Message_DateFormat` was momentarily unloaded — `date-fns` rejects that token because it contains an unescaped `n`. The hook now uses `'LL'` as the default token via `useSetting`'s second argument, so the formatter always receives a valid format string.

apps/meteor/client/hooks/useFormatDate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { useCallback } from 'react';
44
import { formatDate } from '../lib/utils/dateFormat';
55

66
export const useFormatDate = () => {
7-
const format = useSetting('Message_DateFormat');
8-
return useCallback((time: string | Date | number) => formatDate(time, String(format)), [format]);
7+
const format = useSetting('Message_DateFormat', 'LL');
8+
return useCallback((time: string | Date | number) => formatDate(time, format), [format]);
99
};

0 commit comments

Comments
 (0)