Don't await intl-polyfill imports#28779
Conversation
There was a problem hiding this comment.
Pull request overview
This PR attempts to fix an issue where await import("@formatjs/intl-displaynames/polyfill-force") hangs indefinitely in Chrome 143 on macOS when loaded as part of a config panel dependency. The proposed solution removes await keywords from polyfill imports to prevent the blocking behavior.
Key changes:
- Remove
awaitfromintl-localepolyfill import (line 32) - Change from
await Promise.allSettled()to non-awaitedPromise.all()(line 69) - Add
awaittopolyfillLocaleData()call inside the promise chain (line 71)
| } | ||
| if (shouldPolyfillLocale()) { | ||
| await import("@formatjs/intl-locale/polyfill-force"); | ||
| import("@formatjs/intl-locale/polyfill-force"); |
There was a problem hiding this comment.
This fire-and-forget import has no error handling and its result is ignored. If the polyfill import fails silently, it could cause runtime errors when the Intl.Locale API is used. Additionally, there's no guarantee this polyfill will load before the application tries to use the Intl.Locale API, potentially causing race conditions.
| import("@formatjs/intl-locale/polyfill-force"); | |
| polyfills.push(import("@formatjs/intl-locale/polyfill-force")); |
| Promise.all(polyfills).then(async () => { | ||
| // Load the default language | ||
| polyfillLocaleData(locale) | ||
| ); | ||
| await polyfillLocaleData(locale); | ||
| }); |
There was a problem hiding this comment.
The Promise.all result is not awaited, which breaks the async flow of polyfillIntl(). The function will return immediately (line 75 has 'await polyfillIntl()'), but the polyfills won't be loaded yet. This creates a race condition where polyfillLocaleData may execute before the polyfills it depends on are loaded, causing the locale data loading to fail or be skipped since the polyfill __addLocaleData functions won't be available yet.
|
In my build scripts I missed copying this part frontend/build-scripts/bundle.cjs Line 168 in 49bddf6 So with the exclude, it seems to work just fine. Guess the comment above isn't there for no reason 🙃
|
Proposed change
Awaiting
import("@formatjs/intl-displaynames/polyfill-force");in Chrome 143 on macOS 15.6.1 never resolves and dosen't log anything when loading it as part of a config panel dependency (submodule of https://github.com/XKNX/knx-frontend). The project just doesn't load then - an empty tag is rendered instead of the panel.This started with f2aba45
Removing
awaithere fixes this for me.Unfortunately I can't explain why this is happening or what exactly is going on here - and I would be happy if anyone would tell me 😃
For
polyfillLocaleData(locale)- afaict - it doesn't make a difference if awaited or not. Both work fine.Testing
await import("@formatjs/intl-locale/polyfill-force");- although it wouldn't load for my version of Chrome, removing the if-check it would also block indefinitely when using await.await import("@formatjs/intl-getcanonicallocales/polyfill-force");works fine.See also https://discord.com/channels/330944238910963714/1456944554786816154
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: