diff --git a/src/libs/NumberFormatUtils/index.ts b/src/libs/NumberFormatUtils/index.ts index cf04fa6eca56..02bb14b29eed 100644 --- a/src/libs/NumberFormatUtils/index.ts +++ b/src/libs/NumberFormatUtils/index.ts @@ -1,10 +1,9 @@ -import intlPolyfill from '@libs/IntlPolyfill'; import memoize from '@libs/memoize'; import CONST from '@src/CONST'; import type Locale from '@src/types/onyx/Locale'; +import initPolyfill from './intlPolyfill'; -// Polyfill the Intl API if locale data is not as expected -intlPolyfill(); +initPolyfill(); const MemoizedNumberFormat = memoize(Intl.NumberFormat, {maxSize: 10, monitoringName: 'NumberFormatUtils'}); diff --git a/src/libs/NumberFormatUtils/intlPolyfill.ios.ts b/src/libs/NumberFormatUtils/intlPolyfill.ios.ts new file mode 100644 index 000000000000..4745284c0b61 --- /dev/null +++ b/src/libs/NumberFormatUtils/intlPolyfill.ios.ts @@ -0,0 +1,10 @@ +import intlPolyfill from '@libs/IntlPolyfill'; + +// On iOS, polyfills from `additionalSetup` are applied after memoization, which results in incorrect cache entry of `Intl.NumberFormat` (e.g. lacking `formatToParts` method). +// To fix this, we need to apply the polyfill manually before memoization. +// For further information, see: https://github.com/Expensify/App/pull/43868#issuecomment-2217637217 +const initPolyfill = () => { + intlPolyfill(); +}; + +export default initPolyfill; diff --git a/src/libs/NumberFormatUtils/intlPolyfill.ts b/src/libs/NumberFormatUtils/intlPolyfill.ts new file mode 100644 index 000000000000..31fedd6a01b6 --- /dev/null +++ b/src/libs/NumberFormatUtils/intlPolyfill.ts @@ -0,0 +1,2 @@ +const initPolyfill = () => {}; +export default initPolyfill; diff --git a/src/setup/index.ts b/src/setup/index.ts index 6a0e2c4413c3..8c5a32ea170f 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -1,5 +1,6 @@ import {I18nManager} from 'react-native'; import Onyx from 'react-native-onyx'; +import intlPolyfill from '@libs/IntlPolyfill'; import {setDeviceID} from '@userActions/Device'; import initLocale from '@userActions/Locale'; import initOnyxDerivedValues from '@userActions/OnyxDerived'; @@ -63,6 +64,9 @@ export default function () { I18nManager.allowRTL(false); I18nManager.forceRTL(false); + // Polyfill the Intl API if locale data is not as expected + intlPolyfill(); + // Perform any other platform-specific setup platformSetup();