Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/libs/NumberFormatUtils/index.ts
Original file line number Diff line number Diff line change
@@ -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'});

Expand Down
10 changes: 10 additions & 0 deletions src/libs/NumberFormatUtils/intlPolyfill.ios.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions src/libs/NumberFormatUtils/intlPolyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const initPolyfill = () => {};
export default initPolyfill;
4 changes: 4 additions & 0 deletions src/setup/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();

Expand Down
Loading