Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing support for Norwegian locales in Chrome >=92 breaks formatjs #3066

Closed
aglunndexcom opened this issue Jul 21, 2021 · 3 comments
Closed
Labels

Comments

@aglunndexcom
Copy link

aglunndexcom commented Jul 21, 2021

Which package?

This is causing issues in @formatjs/intl-numberformat and @formatjs/intl-datetimeformat, but impacts anywhere that relies on the browser for Intl supported locales.
Polyfilling with @formatjs/intl-pluralrules/should-polyfill can be used to workaround the issue, but only if that polyfill is forced in Chrome with@formatjs/intl-numberformat/polyfill-force.

Describe the bug

Norwegian locales are not currently supported in Google Chrome versions 92 and above, which causes formatjs to fail. The polyfills successfully work around the issue but aren't applied without the (private) polyfill force package because Chrome >= 92 is expected to support these rules.

Here's where the check fails in formatjs:

} else if (!Intl.NumberFormat.supportedLocalesOf(locale).length && onError) {

To Reproduce

Codesandbox URL

Reproducible directly in the browser console window.

Reproducible Steps/Repo

Steps to reproduce the behavior:

  1. Open the console window in dev tools of Chrome >=92
  2. Check for support for Norwegian locales for Intl NumberFormat by running:
    window.Intl.NumberFormat.supportedLocalesOf(['nb-NO', 'nn-NO', 'en-US'])
    (Similarly, window.Intl.DateTimeFormat.supportedLocalesOf(['nb-NO', 'nn-NO', 'en-US']) will check DateTimeFormat).

Expected behavior

Expectation is an array which includes the Norwegian locales: ["nb-NO", "nn-NO", "en-US"]
Actual: ["en-US"]

Desktop (please complete the following information):

  • OS: Any
  • Browser: Chrome
  • Version: >=92

Additional context

There's an existing Chromium bug reported, but we hope that formatjs may be able to work around the issue for users of this project: https://bugs.chromium.org/p/chromium/issues/detail?id=1215606&q=norwegian&can=2

We are able to patch the issue using polyfill-force but that applies the polyfills to all browsers, would formatjs be able to patch this in a more targeted way?

@longlho
Copy link
Member

longlho commented Jul 23, 2021

looks like the fix is to change shouldPolyfill to take in a locale is that right?

@eirslett
Copy link

This helped us:

// polyfills.js
// Chrome 92
// https://bugs.chromium.org/p/chromium/issues/detail?id=1215606&q=norwegian&can=2
// https://github.com/formatjs/formatjs/issues/3066
import '@formatjs/intl-datetimeformat/polyfill-force';
import '@formatjs/intl-datetimeformat/locale-data/en';
import '@formatjs/intl-datetimeformat/locale-data/nb';
import '@formatjs/intl-datetimeformat/locale-data/sv';

import '@formatjs/intl-numberformat/polyfill-force';
import '@formatjs/intl-numberformat/locale-data/en';
import '@formatjs/intl-numberformat/locale-data/nb';
import '@formatjs/intl-numberformat/locale-data/sv';

Seems like once you force the locale polyfill, you have to explicitly polyfill every other language too?

@longlho
Copy link
Member

longlho commented Jul 28, 2021

You can load those dynamically like

if (shouldPolyfill('nb')) {
	import('@formatjs/intl-numberformat/locale-data/nb');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants