Skip to content

Commit a4dec13

Browse files
authored
Preserve warnings when loading translations (#3951)
Previously, we were indiscriminately reseting failed checks every time the editor result changed, including at the initial load of a translation. This fix checks whether the current editor content differs from the initial loaded content before clearing the warnings.
1 parent 5809892 commit a4dec13

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎translate/src/context/Editor.tsx‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,22 +393,21 @@ export function EditorProvider({ children }: { children: React.ReactElement }) {
393393
}, [state, actions, status, machinery.translations]);
394394

395395
useEffect(() => {
396-
// Dismiss failed checks when the results change.
397-
// Note that if the editor is updated simultaneously,
398-
// setting failed checks needs to be delayed past this.
399-
resetFailedChecks();
400-
401396
// Changes in `result` need to be reflected in `UnsavedChanges`,
402397
// but the latter needs to be defined at a higher level to make it
403398
// available in `EntitiesList`. Therefore, that state is managed here.
404399
// Let's also avoid the calculation, unless it's actually required.
405-
setUnsavedChanges(() => {
406-
const { entry, initial, placeholders, sourceView } = state;
407-
const next = sourceView
408-
? parseEntryFromFluentSource(entry, result[0].value)
409-
: buildMessageEntry(entry, placeholders, result);
410-
return !pojoEquals(initial, next);
411-
});
400+
const { entry, initial, placeholders, sourceView } = state;
401+
const next = sourceView
402+
? parseEntryFromFluentSource(entry, result[0].value)
403+
: buildMessageEntry(entry, placeholders, result);
404+
const hasChanges = !pojoEquals(initial, next);
405+
406+
if (hasChanges) {
407+
resetFailedChecks();
408+
}
409+
410+
setUnsavedChanges(() => hasChanges);
412411
}, [result]);
413412

414413
return (

0 commit comments

Comments
 (0)