Skip to content

Commit 79e6ed8

Browse files
committed
Fix fetching unshipped locales when there is no remote base
Choosing a language other than English or Chinese (offered in Settings and by the "DevTools is now available in …" infobar) makes the frontend fetch `./locales/<locale>.json`, which React Native never ships: only `bundled_devtools_locales` are packaged, and the rest are meant to come from Chrome's `remoteBase` CDN, which React Native never passes. The dev server logs `Error: ENOENT: no such file or directory, stat '…/core/i18n/locales/it.json'` on every launch, and the frontend only falls back to English once the failed request comes back. Reject such a locale in `fetchAndRegisterLocaleData` before fetching, so `MainImpl` falls back to `en-US` straight away. Locales served from a remote base, and bundled ones, load as before. Fixes react/react-native#52461 **Test plan** Served `@react-native/debugger-frontend@0.88.0` through `@react-native/dev-middleware@0.88.0` (same `serve-static` setup as Metro) and loaded `rn_fusebox.html` in headless Chrome with `navigator.language` set to `it-IT`. - Before, with the `language` setting `it`: 404 for `locales/it.json`, the server logs the `ENOENT` from the issue, and the frontend warns and renders in English. The same happens with 0.79.5. - With this change applied to the built `core/i18n/i18n.js`, for `it` and `de`: neither file is requested, there is no `ENOENT`, the UI renders in English and the warning gives the new cause. With `zh` the UI still renders in Chinese (`zh.json` 200), and the default setting loads only `en-US.json`. - `npx eslint front_end/core/i18n/i18nImpl.ts` passes, and a scoped `tsc` reports no errors in `front_end/core/i18n/`. The karma unit tests were not run: this checkout has no GN build or depot_tools.
1 parent 3a2e387 commit 79e6ed8

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎front_end/core/i18n/i18nImpl.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ function getLocaleFetchUrl(locale: Intl.UnicodeBCP47LocaleIdentifier, location:
6565
*/
6666
export async function fetchAndRegisterLocaleData(
6767
locale: Intl.UnicodeBCP47LocaleIdentifier, location = self.location.toString()): Promise<void> {
68+
if (!BUNDLED_LOCALES.has(locale) && !Root.Runtime.getRemoteBase(location)?.version) {
69+
throw new Error(`Locale '${locale}' is not bundled and there is no remote base to fetch it from`);
70+
}
6871
const localeDataTextPromise = fetch(getLocaleFetchUrl(locale, location)).then(result => result.json());
6972
const timeoutPromise =
7073
new Promise<never>((_, reject) => window.setTimeout(() => reject(new Error('timed out fetching locale')), 5000));

0 commit comments

Comments
 (0)