#2377·docmost

Editor gets stuck indefinitely after transient collab-token auth failures during fast page/space navigation

Author: Tech-AVARENONECreated Aug 4, 2026Updated Sep 26, 2026

Summary

The real-time editor can get stuck indefinitely (WebSocket never reconnects) after switching between pages or spaces, especially when navigating quickly. The only way to recover is a full page reload.

Root cause

apps/server/src/collaboration/extensions/authentication.extension.ts logs [onAuthenticate] Invalid collab token when the Hocuspocus WebSocket auth handshake is rejected.

On the client, handleAuthenticationFailed in apps/client/src/features/editor/page-editor.tsx only calls refetchCollabToken() when it can locally prove (via jwt-decode) that the cached token has actually expired:

javascript
const handleAuthenticationFailed = () => {
  const payload = jwtDecode(collabQuery?.token);
  const now = Date.now().valueOf() / 1000;
  const isTokenExpired = now >= payload.exp;
  if (isTokenExpired) {
    refetchCollabToken();
  }
};

If the rejection happens for any other reason (e.g. a stale/mismatched token captured during fast page/space navigation, before the token query settles), nothing happens — no retry, no reconnect, no error surfaced to the user. <HocuspocusRoom> (see @hocuspocus/provider-react) already destroys and recreates its provider (which reconnects automatically) whenever its token prop changes, so unconditionally calling refetchCollabToken() here should be sufficient to recover in all cases, not just proven expiry.

Reproduction

  • Self-hosted Docmost via Docker (single instance, Postgres + Redis, behind a Traefik reverse proxy)
  • Reliably reproducible by switching between several pages/spaces in quick succession
  • Server log at the moment of the freeze:
[onAuthenticate] Invalid collab token
  • Confirmed via vmstat/docker stats during a live reproduction that this is not a host resource (CPU/RAM/swap/I-O) or reverse-proxy issue — the request clearly reaches the Docmost server (that's where the log line is written from), so this is purely a client-side recovery gap.

Suggested fix

diff
  const handleAuthenticationFailed = () => {
-   const payload = jwtDecode(collabQuery?.token);
-   const now = Date.now().valueOf() / 1000;
-   const isTokenExpired = now >= payload.exp;
-   if (isTokenExpired) {
-     refetchCollabToken();
-   }
+   refetchCollabToken();
  };

(the now-unused jwt-decode import can be dropped too)

We've been running exactly this patch in production for a few hours now with no further hangs, after previously being able to reproduce the freeze within seconds of navigating. Happy to open a PR with this change if that's useful.