Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Show a single toast on import failure instead of two
Elian Doranedf3c1b01e16
diff --git a/apps/client/src/services/import.ts b/apps/client/src/services/import.tsindex 5edcf7769c..4825e588bd 100644--- a/apps/client/src/services/import.ts+++ b/apps/client/src/services/import.ts@@ -52,7 +52,11 @@ export async function uploadFiles(entityType: string, parentNoteId: string, filetype: "POST",timeout: 60 * 60 * 1000,error: function (xhr) {- toastService.showError(t("import.failed", { message: xhr.responseText }));+ // Fallback toast for failures that never produced a WebSocket `taskError` (e.g. transport or+ // auth errors raised before the importer runs). Deferred so the canonical WebSocket error —+ // emitted alongside this same 500 — can claim the taskId first and win.+ const message = t("import.failed", { message: xhr.responseText });+ setTimeout(() => reportImportError(taskId, message), IMPORT_ERROR_FALLBACK_DELAY);},contentType: false, // NEEDED, DON'T REMOVE THISprocessData: false // NEEDED, DON'T REMOVE THIS@@ -94,14 +98,33 @@ function makeProgressToast(taskId: string, progressCount: number, totalCount?: n};}+/**+ * Shows an import failure exactly once per taskId. A failed import surfaces on two channels: the canonical+ * WebSocket `taskError` message (clean text, paired with the progress toast) and this upload's AJAX error+ * callback (a fallback for failures that never reach the task system). Both route through here, so whichever+ * fires first wins and the duplicate is suppressed.+ */+const IMPORT_ERROR_FALLBACK_DELAY = 500;+const reportedImportErrorTaskIds = new Set<string>();++function reportImportError(taskId: string, message: string) {+ if (reportedImportErrorTaskIds.has(taskId)) {+ return;+ }+ reportedImportErrorTaskIds.add(taskId);+ // Release the taskId once both channels have certainly fired, keeping the guard set bounded.+ setTimeout(() => reportedImportErrorTaskIds.delete(taskId), 60_000);+ toastService.closePersistent(taskId);+ toastService.showError(message);+}+ws.subscribeToMessages(async (message) => {if (!("taskType" in message) || message.taskType !== "importNotes") {return;}if (message.type === "taskError") {- toastService.closePersistent(message.taskId);- toastService.showError(message.message);+ reportImportError(message.taskId, message.message);} else if (message.type === "taskProgressCount") {toastService.showPersistent(makeProgressToast(message.taskId, message.progressCount, message.totalCount));} else if (message.type === "taskSucceeded") {@@ -122,8 +145,7 @@ ws.subscribeToMessages(async (message: WebSocketMessage) => {}if (message.type === "taskError") {- toastService.closePersistent(message.taskId);- toastService.showError(message.message);+ reportImportError(message.taskId, message.message);} else if (message.type === "taskProgressCount") {toastService.showPersistent(makeProgressToast(message.taskId, message.progressCount, message.totalCount));} else if (message.type === "taskSucceeded") {