Skip to content

Build your personal knowledge base with Trilium Notes

feat(ws): add a warning toast if websocket gets disconnected

Elian Doran59ce8b912d4e
diff --git a/apps/client/src/services/ws.ts b/apps/client/src/services/ws.ts
index 79f64c5984..517eb677ef 100644
--- a/apps/client/src/services/ws.ts
+++ b/apps/client/src/services/ws.ts
@@ -7,6 +7,7 @@ import appContext from "../components/app_context.js";
import { t } from "./i18n.js";
import type { EntityChange } from "../server_types.js";
import { WebSocketMessage } from "@triliumnext/commons";
+import toast from "./toast.js";
type MessageHandler = (message: WebSocketMessage) => void;
let messageHandlers: MessageHandler[] = [];
@@ -278,13 +279,17 @@ function connectWebSocket() {
async function sendPing() {
if (Date.now() - lastPingTs > 30000) {
- console.log(
- utils.now(),
- "Lost websocket connection to the backend. If you keep having this issue repeatedly, you might want to check your reverse proxy (nginx, apache) configuration and allow/unblock WebSocket."
- );
+ console.warn(utils.now(), "Lost websocket connection to the backend");
+ toast.showPersistent({
+ id: "lost-websocket-connection",
+ title: t("ws.lost-websocket-connection-title"),
+ message: t("ws.lost-websocket-connection-message"),
+ icon: "no-signal"
+ });
}
if (ws.readyState === ws.OPEN) {
+ toast.closePersistent("lost-websocket-connection");
ws.send(
JSON.stringify({
type: "ping",
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index ebf80297c5..b05979891f 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1787,7 +1787,9 @@
"ws": {
"sync-check-failed": "Sync check failed!",
"consistency-checks-failed": "Consistency checks failed! See logs for details.",
- "encountered-error": "Encountered error \"{{message}}\", check out the console."
+ "encountered-error": "Encountered error \"{{message}}\", check out the console.",
+ "lost-websocket-connection-title": "Lost connection to the server",
+ "lost-websocket-connection-message": "Check your reverse proxy (e.g. nginx or Apache) configuration to ensure WebSocket connections are properly allowed and not being blocked."
},
"hoisted_note": {
"confirm_unhoisting": "Requested note '{{requestedNote}}' is outside of hoisted note '{{hoistedNote}}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?"