Skip to content

Commit

Permalink
[runtime] Return loading promise from _loadLocale when it already e…
Browse files Browse the repository at this point in the history
…xists.

This caused things like `waitForAllDefaultIntlMessagesLoaded` and `loadAllMessagesInLocale` to return true _immediately_ if the locale was _already_ in progress loading, because it wouldn't return the same loading promise, but rather a new one that resolves as soon as the function returns.

Now they should properly wait. To ensure this still escapes early when the locale is already loaded, the existence check has been moved to the top as well.
  • Loading branch information
faultyserver committed Oct 28, 2024
1 parent 2d9f45f commit b2d8368
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/intl/src/message-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ export class MessageLoader {
}

async _loadLocale(locale: LocaleId) {
// If the locale is already set in `messages`, then it doesn't need to be loaded again.
if (this.messages[locale] != null) return;

// Don't re-load a locale that's already in progress.
if (this._localeLoadingPromises[locale]?.current != null) {
await this._localeLoadingPromises[locale]?.current;
return;
}

Expand All @@ -225,9 +229,6 @@ export class MessageLoader {
}
}

// If the locale is already set in `messages`, then it doesn't need to be loaded again.
if (this.messages[locale] != null) return;

const current = this.localeImportMap[locale]();
this._localeLoadingPromises[locale] = { initialized: false, current };
this.messages[locale] = (await current).default;
Expand Down

0 comments on commit b2d8368

Please sign in to comment.