Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(i18n): localize the suspicious overwrite save rejection (#593)

Dariusz Koryto50e4a1a7f296
diff --git a/apps/api/src/memo-service.ts b/apps/api/src/memo-service.ts
index a1de01a9..84b19e79 100644
--- a/apps/api/src/memo-service.ts
+++ b/apps/api/src/memo-service.ts
@@ -10,6 +10,8 @@ import {
resolveMemoContentDoc,
resolveMergedMemoTitle,
isSuspiciousMemoOverwrite,
+ SUSPICIOUS_MEMO_OVERWRITE_ERROR,
+ SUSPICIOUS_MEMO_OVERWRITE_MESSAGE,
isMemoEditBindingValid,
listTableAttachmentResourceIds,
normalizeTags,
@@ -1349,8 +1351,8 @@ export const updateMemoRecord = async (
isSuspiciousMemoOverwrite(current.title, current.content_text, title, contentText)
) {
return {
- error: "suspicious_memo_overwrite",
- message: "Save blocked because the title changed while most of the note content disappeared.",
+ error: SUSPICIOUS_MEMO_OVERWRITE_ERROR,
+ message: SUSPICIOUS_MEMO_OVERWRITE_MESSAGE,
};
}
const tags = input.tags === undefined ? parseJsonArray(current.tags_json) : normalizeTags(input.tags);
diff --git a/apps/mobile/src/lib/mobile-locale.test.mjs b/apps/mobile/src/lib/mobile-locale.test.mjs
index 70b6f9d4..0e64beaf 100644
--- a/apps/mobile/src/lib/mobile-locale.test.mjs
+++ b/apps/mobile/src/lib/mobile-locale.test.mjs
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
-import { localizeMissingNotebookName, localizeUntitledMemoTitle, translateMobileText } from "./mobile-locale.tsx";
+import { localizeMissingNotebookName, localizeUntitledMemoTitle, toMobileSyncErrorSourceText, translateMobileText } from "./mobile-locale.tsx";
describe("mobile locale translation", () => {
test("keeps Chinese copy unchanged for the Chinese locale", () => {
@@ -102,4 +102,13 @@ describe("mobile locale translation", () => {
expect(localizeMissingNotebookName("pl")).toBe("Nieprzypisane");
expect(localizeMissingNotebookName("zh-CN")).toBe("未分类");
});
+
+ test("localizes the suspicious overwrite sync error the server reports in English", () => {
+ const source = toMobileSyncErrorSourceText("Save blocked because the title changed while most of the note content disappeared.");
+ expect(translateMobileText(source, "pl")).toStartWith("Zapis zablokowany");
+ expect(translateMobileText(source, "en-US")).toStartWith("Save blocked: the title changed");
+ expect(translateMobileText(source, "zh-CN")).toStartWith("已阻止保存");
+ expect(toMobileSyncErrorSourceText("Network request failed")).toBe("Network request failed");
+ expect(toMobileSyncErrorSourceText(null)).toBeNull();
+ });
});
diff --git a/apps/mobile/src/lib/mobile-locale.tsx b/apps/mobile/src/lib/mobile-locale.tsx
index 5ec31bfb..f0e15250 100644
--- a/apps/mobile/src/lib/mobile-locale.tsx
+++ b/apps/mobile/src/lib/mobile-locale.tsx
@@ -1,4 +1,4 @@
-import { DEFAULT_MEMO_TITLE } from "@edgeever/shared";
+import { DEFAULT_MEMO_TITLE, getMemoSaveErrorReasonKey } from "@edgeever/shared";
import { enUS, ja, pl, zhCN } from "@edgeever/shared/i18n";
import { resolveSupportedLocale } from "@edgeever/shared/i18n/locales";
import { createContext, useContext, useEffect, useMemo, useState, type ReactNode } from "react";
@@ -838,6 +838,12 @@ export const translateMobileText = (value: string, locale: SupportedMobileLocale
let currentResolvedMobileLocale: SupportedMobileLocale = resolveSystemLocale();
export const translateCurrentMobileText = (value: string) => translateMobileText(value, currentResolvedMobileLocale);
+/** Maps a known English server sync error to its zh-CN source text so the localized components translate it. */
+export const toMobileSyncErrorSourceText = (message: string | null) => {
+ const key = message ? getMemoSaveErrorReasonKey(null, message) : null;
+ return (key && zhStrings.get(key)) || message;
+};
+
export const localizeUntitledMemoTitle = (
title: string | null | undefined,
locale: SupportedMobileLocale,
diff --git a/apps/mobile/src/screens/WorkspaceScreen.tsx b/apps/mobile/src/screens/WorkspaceScreen.tsx
index 3c32437f..666312d9 100644
--- a/apps/mobile/src/screens/WorkspaceScreen.tsx
+++ b/apps/mobile/src/screens/WorkspaceScreen.tsx
@@ -32,7 +32,7 @@ import {
type MobileLocalePreference,
type MobileMemoListDensity,
} from "../lib/preferences";
-import { localizeUntitledMemoTitle, localizeMissingNotebookName, useMobileLocale } from "../lib/mobile-locale";
+import { localizeUntitledMemoTitle, localizeMissingNotebookName, toMobileSyncErrorSourceText, useMobileLocale } from "../lib/mobile-locale";
import { useSession } from "../lib/session";
import {
clearMobileMemoUpdateQueueItem,
@@ -510,7 +510,7 @@ export const WorkspaceScreen = ({
? syncQueueItems.find((item) => item.memoId === selectedMemo.id) ?? null
: null;
const selectedMemoSyncStatus = selectedMemoSyncItem?.status ?? null;
- const selectedMemoSyncError = selectedMemoSyncItem?.lastError ?? null;
+ const selectedMemoSyncError = toMobileSyncErrorSourceText(selectedMemoSyncItem?.lastError ?? null);
const isRefreshing = notebooksQuery.isFetching || memosQuery.isFetching || searchQuery.isFetching || memoDetailQuery.isFetching;
const selectedMemoIdList = Array.from(selectedMemoIds);
const selectedMemos = visibleMemos.filter((memo) => selectedMemoIds.has(memo.id));
diff --git a/apps/web/src/components/DesktopSyncIssuesDialog.tsx b/apps/web/src/components/DesktopSyncIssuesDialog.tsx
index 74a675d9..3beeee1b 100644
--- a/apps/web/src/components/DesktopSyncIssuesDialog.tsx
+++ b/apps/web/src/components/DesktopSyncIssuesDialog.tsx
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { AlertTriangle, ExternalLink, LoaderCircle, RefreshCw, RotateCcw, Trash2 } from "lucide-react";
-import { buildGitHubFeedbackUrl, type DesktopOutboxItem, type Notebook } from "@edgeever/shared";
+import { buildGitHubFeedbackUrl, getMemoSaveErrorReasonKey, type DesktopOutboxItem, type Notebook } from "@edgeever/shared";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
@@ -201,6 +201,7 @@ export const DesktopSyncIssuesDialog = ({
const working = workingId === item.id;
const lastAttemptAt = formatTime(item.updatedAt);
const nextAttemptAt = item.retryable ? formatTime(item.nextAttemptAt) : null;
+ const lastErrorReasonKey = getMemoSaveErrorReasonKey(item.lastErrorCode, item.lastError);
return (
<section key={item.id} className="rounded-lg border border-amber-200 bg-amber-50/60 p-4">
<div className="flex items-start gap-3">
@@ -210,7 +211,7 @@ export const DesktopSyncIssuesDialog = ({
<span className="text-sm font-semibold text-slate-900">{t(operationLabelKey(item.kind), { defaultValue: item.kind })}</span>
<span className="text-xs text-slate-500">{t("notebookPane.syncDetails.attempts", { count: item.attemptCount })}</span>
</div>
- <p className="mt-1 break-words text-sm text-amber-900">{item.lastError || t("notebookPane.syncDetails.unknownError")}</p>
+ <p className="mt-1 break-words text-sm text-amber-900">{lastErrorReasonKey ? t(lastErrorReasonKey) : item.lastError || t("notebookPane.syncDetails.unknownError")}</p>
{item.lastErrorCode ? <p className="mt-1 text-xs text-slate-500">{t("notebookPane.syncDetails.errorCode", { code: item.lastErrorCode })}</p> : null}
{lastAttemptAt ? <p className="mt-1 text-xs text-slate-500">{t("notebookPane.syncDetails.lastAttempt", { time: lastAttemptAt })}</p> : null}
{nextAttemptAt ? <p className="mt-1 text-xs text-slate-500">{t("notebookPane.syncDetails.nextRetry", { time: nextAttemptAt })}</p> : null}
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsx
index cc7fd89f..b24da274 100644
--- a/apps/web/src/components/EditorPane.tsx
+++ b/apps/web/src/components/EditorPane.tsx
@@ -471,6 +471,7 @@ const RichEditorPane = ({
setSaveState,
} = useEditorSaveStatus();
const [storageSaveError, setStorageSaveError] = useState(false);
+ const [saveErrorReasonKey, setSaveErrorReasonKey] = useState<string | null>(null);
const [richTableEditBlocked, setRichTableEditBlocked] = useState(false);
const revertingUnsafeMarkdownRef = useRef(false);
const [hydratedEditorMemoId, setHydratedEditorMemoId] = useState<string | null>(null);
@@ -3016,6 +3017,7 @@ const RichEditorPane = ({
}
setSaveConflictInfo(null);
+ setSaveErrorReasonKey(failure.reasonKey);
setSaveState("error");
},
});
@@ -3582,6 +3584,8 @@ const RichEditorPane = ({
tagsText,
title,
});
+ const saveStatusReason = saveConflictReason
+ ?? (saveState === "error" && saveErrorReasonKey ? t(saveErrorReasonKey) : null);
useLayoutEffect(() => {
const title = headerTitleSlot;
@@ -4020,7 +4024,7 @@ const RichEditorPane = ({
: t("editor.uploadState.fileUploading")}
</span>
)}
- <IconTooltip label={saveConflictReason ? `${saveStatusLabel}. ${saveConflictReason}` : saveStatusLabel}>
+ <IconTooltip label={saveStatusReason ? `${saveStatusLabel}. ${saveStatusReason}` : saveStatusLabel}>
<m.span
key={`${saveState}-${String(hasUnsavedChanges)}`}
className={cn(
@@ -4029,7 +4033,7 @@ const RichEditorPane = ({
)}
role="status"
aria-live="polite"
- aria-label={saveState === "conflict" && saveConflictReason ? `${saveStatusLabel}. ${saveConflictReason}` : saveStatusLabel}
+ aria-label={saveStatusReason ? `${saveStatusLabel}. ${saveStatusReason}` : saveStatusLabel}
{...statusSettleMotion}
>
{saveState === "saving" ? (
@@ -4049,8 +4053,8 @@ const RichEditorPane = ({
className={cn("inline-flex max-w-[5.5rem] truncate rounded-full px-2 py-1 text-xs font-medium sm:hidden", mobileStatusClassName)}
role="status"
aria-live="polite"
- title={saveConflictReason ?? undefined}
- aria-label={saveState === "conflict" && saveConflictReason ? `${saveLabel}. ${saveConflictReason}` : undefined}
+ title={saveStatusReason ?? undefined}
+ aria-label={saveStatusReason ? `${saveLabel}. ${saveStatusReason}` : undefined}
{...statusSettleMotion}
>
{mobileStatusLabel}
diff --git a/apps/web/src/components/editor/editor-save-failure.test.mjs b/apps/web/src/components/editor/editor-save-failure.test.mjs
index 33300424..5dfd7e83 100644
--- a/apps/web/src/components/editor/editor-save-failure.test.mjs
+++ b/apps/web/src/components/editor/editor-save-failure.test.mjs
@@ -54,6 +54,18 @@ describe("classifyEditorSaveFailure", () => {
});
test("falls back to a generic error for unknown failures", () => {
- expect(classifyEditorSaveFailure(new Error("boom"))).toEqual({ kind: "error" });
+ expect(classifyEditorSaveFailure(new Error("boom"))).toEqual({ kind: "error", reasonKey: null });
+ });
+
+ test("explains a save blocked by the suspicious overwrite guard", () => {
+ const error = new MemoSaveRequestError(
+ new ApiRequestError("Save blocked because the title changed while most of the note content disappeared.", 409, "suspicious_memo_overwrite"),
+ queuedPayload,
+ "",
+ );
+ expect(classifyEditorSaveFailure(error)).toEqual({
+ kind: "error",
+ reasonKey: "editor.saveState.errorReason.suspiciousOverwrite",
+ });
});
});
diff --git a/apps/web/src/components/editor/editor-save-failure.ts b/apps/web/src/components/editor/editor-save-failure.ts
index fe374056..b68be357 100644
--- a/apps/web/src/components/editor/editor-save-failure.ts
+++ b/apps/web/src/components/editor/editor-save-failure.ts
@@ -1,3 +1,5 @@
+import { getMemoSaveErrorReasonKey } from "@edgeever/shared";
+import { ApiRequestError } from "@/lib/api";
import { LocalDatabaseUnavailableError } from "@/lib/local-database-recovery";
import { getMemoSaveConflictInfo, type MemoSaveConflictInfo } from "@/lib/memo-save-conflict";
import { shouldQueueMemoSaveError } from "@/lib/sync-queue";
@@ -8,7 +10,7 @@ export type EditorSaveFailure =
| { kind: "storage" }
| { kind: "conflict"; conflict: MemoSaveConflictInfo }
| { kind: "queue"; payload: MemoUpdateSyncPayload; tagsText: string }
- | { kind: "error" };
+ | { kind: "error"; reasonKey: string | null };
export const classifyEditorSaveFailure = (error: unknown): EditorSaveFailure => {
if (error instanceof LocalDatabaseUnavailableError) {
@@ -25,7 +27,10 @@ export const classifyEditorSaveFailure = (error: unknown): EditorSaveFailure =>
return { kind: "queue", payload: error.payload, tagsText: error.tagsText };
}
- return { kind: "error" };
+ return {
+ kind: "error",
+ reasonKey: sourceError instanceof ApiRequestError ? getMemoSaveErrorReasonKey(sourceError.code, sourceError.message) : null,
+ };
};
export const shouldLeaveEditorAfterSaveError = (error: unknown) =>
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index d9ec971e..4b8e87a4 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -2376,6 +2376,9 @@ export const enUS = {
unsaved: "Unsaved",
storageUnavailable: "Browser local storage stopped responding. Keep this page open, close other EdgeEver tabs, then retry. Copy the local draft before clearing any browser data.",
storageRetry: "Retry save",
+ errorReason: {
+ suspiciousOverwrite: "Save blocked: the title changed while most of the note content disappeared. Check the note, copy anything you need, and try again.",
+ },
conflictReason: {
revisionWithVersions: "The cloud note was updated (local base revision {{expected}}, cloud is {{current}}). Common causes: another browser tab, another device, or a cloud change while you were offline. Copy your local draft, then use the cloud version before editing again.",
revision: "The cloud note was updated elsewhere. Common causes: another browser tab, another device, or a cloud change while you were offline. Copy your local draft, then use the cloud version before editing again.",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index b0973645..ba4b3104 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -2365,6 +2365,9 @@ export const ja = {
unsaved: "未保存",
storageUnavailable: "ブラウザのローカルストレージが応答しません。このページは開いたまま、他の EdgeEver タブを閉じてから再試行してください。ブラウザデータを消す前に、ローカル下書きをコピーしてください。",
storageRetry: "保存を再試行",
+ errorReason: {
+ suspiciousOverwrite: "保存をブロックしました: タイトルが変更され、同時にノートの内容の大部分が消えました。ノートを確認し、必要な内容をコピーしてから再試行してください。",
+ },
conflictReason: {
revisionWithVersions: "クラウドのノートが更新されました(ローカル基準の版 {{expected}}、クラウドは {{current}})。よくある原因:別のブラウザタブ、別の端末、オフライン中のクラウド変更です。ローカル下書きをコピーしてから、クラウド版を使って編集を続けてください。",
revision: "クラウドのノートが他で更新されました。よくある原因:別のブラウザタブ、別の端末、オフライン中のクラウド変更です。ローカル下書きをコピーしてから、クラウド版を使って編集を続けてください。",
diff --git a/packages/shared/src/i18n/pl.ts b/packages/shared/src/i18n/pl.ts
index 5d61c8c1..e9ac0d17 100644
--- a/packages/shared/src/i18n/pl.ts
+++ b/packages/shared/src/i18n/pl.ts
@@ -2365,6 +2365,9 @@ export const pl = {
unsaved: "Niezapisane",
storageUnavailable: "Lokalny magazyn przeglądarki przestał odpowiadać. Nie zamykaj tej strony, zamknij inne karty EdgeEver i spróbuj ponownie. Zanim wyczyścisz dane przeglądarki, skopiuj lokalny szkic.",
storageRetry: "Ponów zapis",
+ errorReason: {
+ suspiciousOverwrite: "Zapis zablokowany: zmieniono tytuł, a jednocześnie zniknęła większość treści notatki. Sprawdź notatkę, skopiuj potrzebną treść i spróbuj ponownie.",
+ },
conflictReason: {
revisionWithVersions: "Notatka w chmurze została zaktualizowana (lokalna wersja bazowa {{expected}}, w chmurze {{current}}). Najczęstsze przyczyny: inna karta przeglądarki, inne urządzenie lub zmiana w chmurze podczas pracy offline. Skopiuj lokalny szkic, a potem użyj wersji z chmury, zanim zaczniesz ponownie edytować.",
revision: "Notatka w chmurze została zaktualizowana w innym miejscu. Najczęstsze przyczyny: inna karta przeglądarki, inne urządzenie lub zmiana w chmurze podczas pracy offline. Skopiuj lokalny szkic, a potem użyj wersji z chmury, zanim zaczniesz ponownie edytować.",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 7ca674a6..a96196b6 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -2376,6 +2376,9 @@ export const zhCN = {
unsaved: "未保存",
storageUnavailable: "浏览器本地存储无响应。请保持当前页面打开,关闭其他 EdgeEver 标签页后重试。清除浏览器数据前请先复制本地草稿。",
storageRetry: "重试保存",
+ errorReason: {
+ suspiciousOverwrite: "已阻止保存:标题被修改,同时笔记的大部分内容消失。请检查笔记并复制需要保留的内容后重试。",
+ },
conflictReason: {
revisionWithVersions: "云端笔记已更新(本地基于版本 {{expected}},云端已是 {{current}})。常见原因:其他标签页、其他设备,或离线期间云端被改过。可先复制本地草稿,再采用云端版本后继续编辑。",
revision: "云端笔记已在其他位置被更新。常见原因:其他标签页、其他设备,或离线期间云端被改过。可先复制本地草稿,再采用云端版本后继续编辑。",
diff --git a/packages/shared/src/memo-safety.test.mjs b/packages/shared/src/memo-safety.test.mjs
index 442d074d..d8b3633d 100644
--- a/packages/shared/src/memo-safety.test.mjs
+++ b/packages/shared/src/memo-safety.test.mjs
@@ -1,5 +1,10 @@
import { describe, expect, test } from "bun:test";
-import { isMemoEditBindingValid, isSuspiciousMemoOverwrite } from "./memo-safety.ts";
+import {
+ getMemoSaveErrorReasonKey,
+ isMemoEditBindingValid,
+ isSuspiciousMemoOverwrite,
+ SUSPICIOUS_MEMO_OVERWRITE_MESSAGE,
+} from "./memo-safety.ts";
describe("isSuspiciousMemoOverwrite", () => {
test("blocks the production incident shape", () => {
@@ -65,3 +70,16 @@ describe("isMemoEditBindingValid", () => {
expect(isMemoEditBindingValid(current, session, { ...request, editSessionId: "edit_2" })).toBe(false);
});
});
+
+describe("getMemoSaveErrorReasonKey", () => {
+ test("maps the suspicious overwrite rejection by code or by its server message", () => {
+ const key = "editor.saveState.errorReason.suspiciousOverwrite";
+ expect(getMemoSaveErrorReasonKey("suspicious_memo_overwrite")).toBe(key);
+ expect(getMemoSaveErrorReasonKey(null, ` ${SUSPICIOUS_MEMO_OVERWRITE_MESSAGE} `)).toBe(key);
+ });
+
+ test("leaves other errors to their original message", () => {
+ expect(getMemoSaveErrorReasonKey("memo_not_found", "Memo not found")).toBeNull();
+ expect(getMemoSaveErrorReasonKey(null, null)).toBeNull();
+ });
+});
diff --git a/packages/shared/src/memo-safety.ts b/packages/shared/src/memo-safety.ts
index 0e70c232..6b52a320 100644
--- a/packages/shared/src/memo-safety.ts
+++ b/packages/shared/src/memo-safety.ts
@@ -23,3 +23,16 @@ export const isMemoEditBindingValid = (
session.baseRevision === current.revision &&
request.expectedContentHash === current.contentHash &&
session.baseContentHash === current.contentHash;
+
+export const SUSPICIOUS_MEMO_OVERWRITE_ERROR = "suspicious_memo_overwrite";
+export const SUSPICIOUS_MEMO_OVERWRITE_MESSAGE =
+ "Save blocked because the title changed while most of the note content disappeared.";
+
+/**
+ * i18n key for a save rejection the server reports in English. The mobile sync
+ * queue stores only the message, so the message is matched as well as the code.
+ */
+export const getMemoSaveErrorReasonKey = (code: string | null | undefined, message?: string | null) =>
+ code === SUSPICIOUS_MEMO_OVERWRITE_ERROR || message?.trim() === SUSPICIOUS_MEMO_OVERWRITE_MESSAGE
+ ? "editor.saveState.errorReason.suspiciousOverwrite"
+ : null;