fix: Tidy up i18nextTranslationApi change handling
This change removes some extra logic in i18NextTranslationApi's change handling to ensure it always updates subscribers when a language change is handled. The relevant test was updated so it doesn't expect snapshots that aren't loaded. Fixes #20381 Signed-off-by: Stan Lewis <gashcrumb@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/core-app-api': patch
|
||||
---
|
||||
|
||||
Fixed a bug in i18nextTranslationApi where in some cases it wouldn't notify subscribers of language changes
|
||||
+1
-2
@@ -377,8 +377,7 @@ describe('I18nextTranslationApi', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
expect(translations).toEqual(['foo', null, 'Föö', null, 'Føø']);
|
||||
expect(translations).toEqual(['foo', 'Föö', 'Føø']);
|
||||
});
|
||||
|
||||
describe('formatting', () => {
|
||||
|
||||
+3
-8
@@ -241,7 +241,6 @@ export class I18nextTranslationApi implements TranslationApi {
|
||||
|
||||
return new ObservableImpl<TranslationSnapshot<TMessages>>(subscriber => {
|
||||
let loadTicket = {}; // To check for stale loads
|
||||
let lastSnapshotWasReady = false;
|
||||
|
||||
const loadResource = () => {
|
||||
loadTicket = {};
|
||||
@@ -250,8 +249,7 @@ export class I18nextTranslationApi implements TranslationApi {
|
||||
() => {
|
||||
if (ticket === loadTicket) {
|
||||
const snapshot = this.#createSnapshot(internalRef);
|
||||
if (snapshot.ready || lastSnapshotWasReady) {
|
||||
lastSnapshotWasReady = snapshot.ready;
|
||||
if (snapshot.ready) {
|
||||
subscriber.next(snapshot);
|
||||
}
|
||||
}
|
||||
@@ -266,12 +264,9 @@ export class I18nextTranslationApi implements TranslationApi {
|
||||
|
||||
const onChange = () => {
|
||||
const snapshot = this.#createSnapshot(internalRef);
|
||||
if (lastSnapshotWasReady && !snapshot.ready) {
|
||||
lastSnapshotWasReady = snapshot.ready;
|
||||
if (snapshot.ready) {
|
||||
subscriber.next(snapshot);
|
||||
}
|
||||
|
||||
if (!snapshot.ready) {
|
||||
} else {
|
||||
loadResource();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user