Merge pull request #20567 from gashcrumb/update-change-handler
fix: Tidy up i18nextTranslationApi change handling
This commit is contained in:
@@ -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.
|
||||
+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