-
Notifications
You must be signed in to change notification settings - Fork 136
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
Safari 14 Intl.NumberFormat usage throwing "Error: locale data nu must be an object" #886
Comments
I have the same issue in Safari 13 with |
The issue here is that you're polyfilling The Intl.NumberFormat polyfill is ES2020 which Safari 14 does not have. This explains why the polyfill was activated. |
Hi, I'm getting the same error with polyfills for 'no' locale. @longlho thanks for the workaround with v3.89.4. I'm sure the reason is that in For example in this polyfill https://cdn.polyfill.io/v3/polyfill.js?features=Intl.PluralRules.~locale.nb&version=3.89.4 you can find 'aliases' variable and it is used in I wonder would it be possible to support custom locale data for locales that are not supported by polyfill service? |
aliases are used to resolve legacy locales like zh-CN -> zh-Hans-CN so it's not related to this problem. The old behavior was that en data is shipped all the time for all locales as it's the fallback, which you can imagine isn't ideal, esp for big API like Intl.NumberFormat |
To answer your question, technically it is possible to use custom locale data but it's an implementation detail of the polyfills and changes frequently as normative specs are changed. CLDR data is also preprocessed and packed to reduce size as well. At the end of the day there's __addLocaleData method in the polyfilled version but I highly discourage using it |
@JakeChampion this is actually working as designed |
@longlho I still think this error message should be more helpful. Is it possible to produce a message that states :
This would at least give developers a way to resolve this issue without coming here. |
@longlho Thank you for responding and looking into this. Am I right to assume your recommendation to avoid this issue would be to either always use the To clarify regarding Safari 14 not supporting According to the previously linked kangax table and Can I use, it would seem Safari 14 fully supports this API. It also seems to work without the polyfill when just running in the Safari 14 console: While deciding this is behaving as intended is perfectly reasonable of course, I feel I should clarify why this originally seemed like a bug:
I personally believe most users would prefer a simpler and safer configuration over a performance gain. |
@romainmenke yes can you create a GH issue over at formatjs to fix the err message? @ronenst there're several issues with just picking a default locale:
So size is not the only issue but it is indeed a big issue. Locale data for en is pretty big (~20/30K but don't quote me on that). At a high level by not specifying a locale you basically guarantee your product works correctly in ALL 200+ locales that browsers throw at you. On top of that locale negotiation is not a straightforward lookup it's a hierarchy-based lookup. E.g if you ask for Polish and browsers don't have it it's at its own liberty to pick literally whatever it thinks work best (best-fit locale lookup). So it could be french or german or english. My recommendation is to fix the callsite to always be explicit about picking a locale and make sure you test against that and have monitoring around it. |
Thanks, will look into that although it may not always be possible to control that, for example, when using a 3rd party library which calls this API. |
If a 3rd party i18n library decides to pick a locale for you and don't allow you to override I recommend not using that :) personally I haven't seen it since i18n space is fairly complex so there're less options out there. In terms of Safari 14 supporting Intl.NumberFormat. It does support it, but a es5 version and the polyfill is for es2020 version |
@longlho and @romainmenke thank you for taking the time to handle this issue 👍 |
Bug Report
What
Trying to initialize an
Intl.NumberFormat
object in Safari 14 with the latest version of the polyfill loaded throws an exception.Details
Browser
Safari (Desktop) Version 14.0 (15610.1.28.1.9, 15610)
Minimal code example
https://jsbin.com/xikuwesiru/edit?html,console
Expected result
Console logs:
1,000
Actual result
Error: locale data nu must be an object
is thrown.Possible workaround for users of pollyfill.io service
Set the library to an earlier version without these polyfills: (i.e. https://polyfill.io/v3/polyfill.min.js?features=Intl.~locale.ja&version=3.89.4)
More info
polyfill-service
releaseThe text was updated successfully, but these errors were encountered: