Merge pull request #20567 from gashcrumb/update-change-handler

fix: Tidy up i18nextTranslationApi change handling
This commit is contained in:
Patrik Oldsberg
2023-10-12 16:33:10 +02:00
committed by GitHub
3 changed files with 9 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/core-app-api': patch
---
Fixed a bug in `TranslationApi` implementation where in some cases it wouldn't notify subscribers of language changes.
@@ -377,8 +377,7 @@ describe('I18nextTranslationApi', () => {
},
});
});
expect(translations).toEqual(['foo', null, 'Föö', null, 'Føø']);
expect(translations).toEqual(['foo', 'Föö', 'Føø']);
});
describe('formatting', () => {
@@ -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();
}
};