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
fix(text): bring the editor error toast back after its details close
Elian Dorana406fc659bfc
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts b/apps/client/src/widgets/type_widgets/text/EditableText.spec.tsindex 140bf146c3..832f176e71 100644--- a/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts+++ b/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts@@ -82,6 +82,29 @@ describe("reportEditorError", () => {expect(JSON.stringify(showInfoDialog.mock.calls[0][0])).toContain("TypeError: boom");vi.unstubAllGlobals();});++ it("shows the toast again once the details dialog closes, so the editor can still be reloaded", async () => {+ vi.clearAllMocks();+ let closeDialog = () => {};+ showInfoDialog.mockImplementationOnce(() => new Promise<void>((resolve) => {+ closeDialog = resolve;+ }));+ const reloadEditor = vi.fn();++ reportEditorError(new Error("unexpected-error") as CKEditorError, reloadEditor);+ const [ { buttons } ] = showPersistent.mock.calls[0];+ buttons[1].onClick({ dismissToast: vi.fn() });++ await Promise.resolve();+ expect(showPersistent).toHaveBeenCalledOnce();++ closeDialog();+ await vi.waitFor(() => expect(showPersistent).toHaveBeenCalledTimes(2));+ const [ { id, buttons: buttonsAgain } ] = showPersistent.mock.calls[1];+ expect(id).toBe("editor-error");+ buttonsAgain[0].onClick({ dismissToast: vi.fn() });+ expect(reloadEditor).toHaveBeenCalledOnce();+ });});describe("onNotificationWarning", () => {diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsxindex 8ecfa1ccb0..ec9a42530b 100644--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx@@ -762,8 +762,9 @@ function useTemplates() {/*** Tells the user about an error that escaped the editor in a toast, which offers to reload the- * editor and opens the error details for a bug report. The editor keeps running until then, so a- * later error replaces the toast. The global error handlers in `glob.ts` log the error.+ * editor and opens the error details for a bug report; the toast returns once the details close.+ * The editor keeps running until it is reloaded, so a later error replaces the toast. The global+ * error handlers in `glob.ts` log the error.** Exported for testing.*/@@ -774,36 +775,41 @@ export function reportEditorError(error: CKEditorError, reloadEditor: () => voiddate: new Date().toISOString()}, null, 4);- toast.showPersistent({- id: "editor-error",- icon: "bx bx-bug",- title: t("editable_text.editor_error_title"),- message: t("editable_text.editor_error_content"),- buttons: [- {- text: t("editable_text.editor_error_reload_button"),- onClick: ({ dismissToast }) => {- dismissToast();- reloadEditor();- }- },- {- text: t("editable_text.editor_crashed_details_button"),- onClick: ({ dismissToast }) => {- dismissToast();- dialog.info(<>- <p>{t("editable_text.editor_crashed_details_intro")}</p>- <h3>{t("editable_text.editor_crashed_details_title")}</h3>- <pre><code class="language-application-json">{details}</code></pre>- </>, {- title: t("editable_text.editor_error_title"),- size: "lg",- copyToClipboardButton: true- });+ showErrorToast();++ function showErrorToast() {+ toast.showPersistent({+ id: "editor-error",+ icon: "bx bx-bug",+ title: t("editable_text.editor_error_title"),+ message: t("editable_text.editor_error_content"),+ buttons: [+ {+ text: t("editable_text.editor_error_reload_button"),+ onClick: ({ dismissToast }) => {+ dismissToast();+ reloadEditor();+ }+ },+ {+ text: t("editable_text.editor_crashed_details_button"),+ onClick: async ({ dismissToast }) => {+ dismissToast();+ await dialog.info(<>+ <p>{t("editable_text.editor_crashed_details_intro")}</p>+ <h3>{t("editable_text.editor_crashed_details_title")}</h3>+ <pre><code class="language-application-json">{details}</code></pre>+ </>, {+ title: t("editable_text.editor_error_title"),+ size: "lg",+ copyToClipboardButton: true+ });+ showErrorToast();+ }}- }- ]- });+ ]+ });+ }}/**