From 718fd3ad22ccae115596ce2f9f2906cdbf207419 Mon Sep 17 00:00:00 2001 From: AlexisG Date: Fri, 20 Dec 2024 13:44:17 +0100 Subject: [PATCH] fix(initFormat): Ensure do not crash if no date is passed Since version 115.0.0, the new version of `date-fns` throws an error if no date has passed. In order to maintain the same behavior on our apps, we make sure we don't throw any errors in the apps. --- react/providers/I18n/format.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/react/providers/I18n/format.jsx b/react/providers/I18n/format.jsx index 4837b825e..2b494d351 100644 --- a/react/providers/I18n/format.jsx +++ b/react/providers/I18n/format.jsx @@ -53,7 +53,11 @@ export const initFormat = const locale = provideDateFnsLocale(userLang, defaultLang) const ensureDate = date && typeof date === 'string' ? new Date(date) : date - return format(ensureDate, formatStr, { locale, ...opts }) + try { + return format(ensureDate, formatStr, { locale, ...opts }) + } catch (error) { + console.error('Error in initFormat', error) + } } export const formatLocallyDistanceToNow = date => {