From ebd9f05f69211c484ac791e54e7ca2d187a2f50b Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 3 Apr 2024 14:33:53 +0800 Subject: [PATCH] Preload IntlSegmenter polyfill if needed --- src/components/intl-segmenter-suspense.jsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/components/intl-segmenter-suspense.jsx b/src/components/intl-segmenter-suspense.jsx index 9e56ab1e..e015401e 100644 --- a/src/components/intl-segmenter-suspense.jsx +++ b/src/components/intl-segmenter-suspense.jsx @@ -6,6 +6,15 @@ import Loader from './loader'; const supportsIntlSegmenter = !shouldPolyfill(); +// Preload IntlSegmenter +setTimeout(() => { + queueMicrotask(() => { + if (!supportsIntlSegmenter) { + import('@formatjs/intl-segmenter/polyfill-force').catch(() => {}); + } + }); +}, 1000); + export default function IntlSegmenterSuspense({ children }) { if (supportsIntlSegmenter) { return }>{children};