core-app-api: avoid trying to load failed translations again

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-09-16 12:33:46 +02:00
parent 7b3a58f0b6
commit 83fb7c5e16
2 changed files with 14 additions and 5 deletions
@@ -255,7 +255,7 @@ describe('I18nextTranslationApi', () => {
expect(snapshot.t('bar')).toBe('Bär');
});
it('should forward loading errors', async () => {
it('should forward loading errors and then ignore them', async () => {
const languageApi = AppLanguageSelector.create();
const translationApi = I18nextTranslationApi.create({
languageApi,
@@ -270,6 +270,9 @@ describe('I18nextTranslationApi', () => {
await expect(
waitForNext(translationApi.translation$(plainRef), s => s.ready),
).rejects.toThrow('NOPE');
const snapshot = assertReady(translationApi.getTranslation(plainRef));
expect(snapshot.t('foo')).toBe('Foo');
});
it('should only call the loader once', async () => {
@@ -121,10 +121,16 @@ class ResourceLoader {
return;
}
const load = loader().then(result => {
this.onLoad({ language, namespace, messages: result.messages });
this.#loaded.add(key);
});
const load = loader().then(
result => {
this.onLoad({ language, namespace, messages: result.messages });
this.#loaded.add(key);
},
error => {
this.#loaded.add(key); // Do not try to load failed resources again
throw error;
},
);
this.#loading.set(key, load);
await load;
}