Skip to content

Build your personal knowledge base with Trilium Notes

fix(core): race condition in language change

Elian Doran489bb91822ec
diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.ts
index ecdb7ba2f4..2aef6e4e0a 100644
--- a/packages/trilium-core/src/routes/api/options.ts
+++ b/packages/trilium-core/src/routes/api/options.ts
@@ -142,15 +142,19 @@ function getOptions() {
return resultMap;
}
-function updateOption(req: Request<{ name: string; value: string }>) {
+async function updateOption(req: Request<{ name: string; value: string }>) {
const { name, value } = req.params;
if (!update(name, value)) {
throw new ValidationError("not allowed option to change");
}
+
+ if (name === "locale") {
+ await changeLanguage(value);
+ }
}
-function updateOptions(req: Request) {
+async function updateOptions(req: Request) {
for (const optionName in req.body) {
if (!update(optionName, req.body[optionName])) {
// this should be improved
@@ -158,6 +162,10 @@ function updateOptions(req: Request) {
throw new Error(`Option '${optionName}' is not allowed to be changed`);
}
}
+
+ if ("locale" in req.body) {
+ await changeLanguage(req.body["locale"]);
+ }
}
function update(name: string, value: string) {
@@ -171,11 +179,6 @@ function update(name: string, value: string) {
optionService.setOption(name as OptionNames, value);
- if (name === "locale") {
- // This runs asynchronously, so it's not perfect, but it does the trick for now.
- changeLanguage(value);
- }
-
return true;
}