Skip to content

Commit cc13ae7

Browse files
fix: aligns first render for hydration of dates in list view (#10541)
### What? The list view was throwing a hydration error for date fields. ### Why? The issue really stems from the fact that cells are client rendered. We dynamically load the dateFNS Locale object at runtime to keep the bundle size small — which makes sense. But on the first render that means we do not have the Locale object from the known locale so the server/client determines what to render it as. This causes a mismatch when hydrating. In the future I think cells could be server rendered and that would solve the need for this fix which adds "Loading..." while the dateFNS Locale is loaded. I think server rendering the cells would allow us to import the dateFNS Locale inline (blocking) and then pass the rendered string down to the list view. This should work because we **know** the locale on the server. ### How? In this PR, it adds a "Loading..." fallback for the date cell if the dateFNS Locale has not loaded yet. Fixes #10044
1 parent afcc970 commit cc13ae7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/ui/src/utilities/formatDate.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type FormatDateArgs = {
1010

1111
export const formatDate = ({ date, i18n, pattern }: FormatDateArgs): string => {
1212
const theDate = new Date(date)
13-
return format(theDate, pattern, { locale: i18n.dateFNS })
13+
return i18n.dateFNS
14+
? format(theDate, pattern, { locale: i18n.dateFNS })
15+
: `${i18n.t('general:loading')}...`
1416
}
1517

1618
type FormatTimeToNowArgs = {
@@ -20,5 +22,7 @@ type FormatTimeToNowArgs = {
2022

2123
export const formatTimeToNow = ({ date, i18n }: FormatTimeToNowArgs): string => {
2224
const theDate = new Date(date)
23-
return formatDistanceToNow(theDate, { locale: i18n.dateFNS })
25+
return i18n?.dateFNS
26+
? formatDistanceToNow(theDate, { locale: i18n.dateFNS })
27+
: `${i18n.t('general:loading')}...`
2428
}

0 commit comments

Comments
 (0)