Files
wekan/models/lib/openCardPresence.js
T
Lauri Ojansivu 7ed3ca7c5c A card opened from its link stays open when the connection drops and comes back while the page loads.
Behind a reverse proxy the DDP connection can drop and come back while a
card's link is still loading (a WebSocket upgrade the proxy refuses,
SockJS falling back). Every subscription re-runs on the way back, one
answers before the resumed login with nothing, and the card leaves
Minimongo for a moment. #3114's close-on-removal took that moment for a
deletion: it closed the card and went to the board's address.

The window now waits while the subscription, the connection or the login
is settling, and when the card looks gone with everything settled, asks
the server (cards.openCardAvailable, the 'card' publication's own rule,
now one function in server/lib/openCardAccess.js) and closes only on its
no, if Minimongo still agrees. A card really deleted, archived or moved
elsewhere still closes. Not reproduced here: no proxy in this
environment; the browser test drops and restores the connection.

Thanks to brlin-tw and xet7 !

Fixes #6808.
2026-10-27 10:05:01 +02:00

33 lines
1.6 KiB
JavaScript

'use strict';
// Decide whether a card-details window still belongs on the board where it was
// opened. A missing card means another client deleted/archived it (or moved it
// outside the current publication); a changed boardId means it was moved to a
// different board while another subscription still happens to retain it.
function openCardIsUnavailable(card, openedBoardId) {
return !card || !openedBoardId || card.boardId !== openedBoardId;
}
// #6808: what the opened card's window does about what Minimongo says now.
//
// A card missing from Minimongo is not yet a card that is gone. Behind a
// reverse proxy the DDP connection can drop and come back while the page is
// still loading (a WebSocket upgrade the proxy refuses, SockJS falling back);
// on the way back every subscription is re-run, and one re-run before the
// resumed login answers with nothing - the card leaves Minimongo for a moment
// and comes back. Closing on that moment closed a card the link had just
// opened. So:
//
// 'keep' - the card is here, on the board it was opened on;
// 'wait' - something is still settling (the subscription, the
// connection, the login): decide when it has;
// 'confirm' - it looks gone with everything settled: ask the server, and
// close only if the server says so and Minimongo still agrees.
function openCardCloseDecision({ subReady, connected, loggingIn, card, openedBoardId }) {
if (!openCardIsUnavailable(card, openedBoardId)) return 'keep';
if (!subReady || !connected || loggingIn) return 'wait';
return 'confirm';
}
module.exports = { openCardIsUnavailable, openCardCloseDecision };