Server Side formatting #1995
Replies: 2 comments 4 replies
-
|
In the thread you've linked to, there's some relevant information here: #1708 (comment) If the issue appears because of a browser bug, potentially another option for you could be to either find a locale config that avoids the issue or if it's an option, ensure that the formatting only runs in RSC. There's also more on this here: Reliable date formatting in Next.js |
Beta Was this translation helpful? Give feedback.
-
|
I cannot get this to work at all. The issue is Icelandic locale and Chromium browsers which are the biggest part of the userbase for the current app. Polyfilling via CDN provided libraries do not work. They incorrectly say no polyfill is needed. in theory this code might work import { shouldPolyfill } from '@formatjs/intl-numberformat/should-polyfill';
export async function polyfillIntl(locale: string) {
const unsupportedLocale = shouldPolyfill(locale);
// This locale is supported
if (!unsupportedLocale) {
return;
}
try {
// Load the polyfill 1st BEFORE loading data
await import('@formatjs/intl-numberformat/polyfill-force');
await import(`@formatjs/intl-numberformat/locale-data/${unsupportedLocale}`);
await import('@formatjs/intl-datetimeformat/polyfill-force');
// Parallelize CLDR data loading
const dataPolyfills = [
import('@formatjs/intl-datetimeformat/add-all-tz'),
import(`@formatjs/intl-datetimeformat/locale-data/${unsupportedLocale}`),
];
await Promise.all(dataPolyfills);
console.log(`Intl polyfills loaded for locale: ${unsupportedLocale}`);
} catch (error) {
console.error('Failed to load Intl polyfills:', error);
}
}But how to run this on the clientside of a Nextjs application before rendering essentially to ensure no issue. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is the Formatter not available server side?
How does hydration work here? Is the server side rendering using Intl.Formatter ?
Taking a look at this issue f.e.
1708
Hydration is failing on Chrome when using format on the client side.
Icelandic has the same issue, is-IS just isn´t supported in Chromium and making a ticket is not a good suggestions since one has existed for a decade and nothing happens.
This is one of the main reasons I reach for a library like Next-Intl. There might be a translation plan as well, but formatting numbers and dates is the main issue.
So what is going on here server side?
Beta Was this translation helpful? Give feedback.
All reactions