core-app-api: avoid trying to load failed translations again
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
+4
-1
@@ -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 () => {
|
||||
|
||||
+10
-4
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user