mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Two problems from one report with screenshots, both in how a list decides what to
draw at its bottom edge.
1. "ONCE A FILTER IS APPLIED FOR A MEMBER, THE 3 DOTS CONTINUE TO ANIMATE." The
screenshot shows a list with NO cards under the filter and the load-more spinner
still turning under it - and `_updateList` raising the window limit by ten every
idle callback for as long as it stayed on screen.
The spinner asked "does this list hold more cards than the window I asked for?"
and answered it from a total built somewhere else than the cards being drawn. The
cards come from the filtered selector; the total came either from
`list.cards(swimlaneId).length` or, in lazy card-loading mode, from a count
document published per list/swimlane - whose id was `listId::swimlaneId` and did
NOT include the filter. So changing the filter re-subscribed with a new selector
under the SAME document id, two publications wrote one document, and Meteor's
merge box serves whichever subscription it prefers, which during the changeover is
the older, pre-filter one. The list drew its empty filtered window while its count
still described the unfiltered list.
The count document now carries a short stable key for its selector, so each filter
counts into its own document and a count can never describe another filter's
cards. Both subscribers pass it; the two-argument form still returns the old id
for a caller with no selector to hand.
And the spinner no longer depends on that being right. There is nothing more to
fetch unless the window came back FULL: if we asked for twenty cards and got
three, those three are all there are, whatever any count says. That holds in both
card-loading modes and for a stale count in either direction, which is why it is
worth asking as well as the total.
While there: showSpinner asked `isLazyCards()` with no board while cardsWithLimit
asked `isLazyCards(list.boardId)`, so the two could take different branches for
the same list. Both ask about the board now, and both build the selector the same
way instead of from different sources - that disagreement was the bug.
2. "RANDOM BLANK CARDS ARE APPEARING ON THE BOARD." White minicards with the
handle icon and nothing else - no title, no members, no labels - mixed in among
the real ones. In the screenshot the only two that render are the two carrying the
viewer's own avatar.
A minicard renders blank when its document is in minimongo without its fields:
`Cards.getTitle()` returns null for `title === undefined`, and every badge is
conditional on a field that is not there either. That is NOT a card with an empty
title - the schema declares `title` as optional with `defaultValue: ''`, so a card
that went through it has the key, `''` at worst. A document without the key at all
is a partial replication, and several publications ship cards with a projection:
`openCardData` publishes `{ _id: 1 }` as the parent of its children cursors, the
search publications ship their own field lists, and minimongo merges what every
live publication says about an id.
WHICH of them produced these particular stubs is not settled - it needs the
running board to catch - so this is a guard where the card is drawn rather than a
fix at the source: a document that does not carry the field the minicard is built
around is not drawn. `$exists` is what separates the two cases; filtering on a
falsy title would hide real cards. It cannot hide a card, and when the full
document arrives the card appears, which is what the blank box was standing in for
anyway.
tests/listCardWindow.test.cjs covers the reported case (a filter empties the list
and the total still says 25), a short window in general, that a full window with
more behind it still offers to load more, a stale total in both directions,
missing input, that an empty title is still drawn while a missing one is not, that
the selector stays flat and an existing `title` clause is not silently replaced,
that two filters no longer share a count document while the same filter always
names one whatever order it was built in, and that every subscriber names it the
same way.
Thanks to xet7 !
75 lines
4.0 KiB
JavaScript
75 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
// Two decisions a board's card list makes on every render, pulled out of the
|
|
// Blaze helpers so they can be unit-tested in plain Node (mirrors
|
|
// client/lib/cardDragGeometry.js).
|
|
|
|
// ── the "load more" spinner ──────────────────────────────────────────────────
|
|
//
|
|
// A member filter left the spinner turning forever at the bottom of a list that
|
|
// had NO cards under that filter, and `_updateList` kept raising the window limit
|
|
// underneath it for as long as it stayed on screen.
|
|
//
|
|
// The spinner asked one question — "does the list hold more cards than the window
|
|
// I asked for?" — and answered it from a total that could disagree with what is
|
|
// actually on screen. In lazy card-loading mode that total comes from a count
|
|
// document published per list/swimlane, and the document's id did not include the
|
|
// filter, so a filter change re-subscribed with a new selector under the SAME id
|
|
// and the pre-filter count could stay (see models/lib/cardsLoading.js). The
|
|
// filtered list then rendered nothing while the count still said "25 cards".
|
|
//
|
|
// The count is fixed there; here is the answer that does not depend on it. There
|
|
// is nothing more to fetch unless the window we asked for came back FULL: if we
|
|
// asked for 20 cards and got 3, those 3 are all there are, whatever any count
|
|
// says. That holds in both card-loading modes and for a stale count in either
|
|
// direction, which is what makes it worth asking as well as the total.
|
|
function shouldShowLoadMoreSpinner({ total, loaded, limit } = {}) {
|
|
const lim = Number.isFinite(limit) ? limit : 0;
|
|
const got = Number.isFinite(loaded) ? loaded : 0;
|
|
const all = Number.isFinite(total) ? total : 0;
|
|
|
|
// No window asked for yet: nothing to say about a next one.
|
|
if (lim <= 0) return false;
|
|
// The window came back short, so it is the whole list. This is the one that
|
|
// stops a stale total turning the spinner forever.
|
|
if (got < lim) return false;
|
|
|
|
return all > lim;
|
|
}
|
|
|
|
// ── which card documents may be drawn ────────────────────────────────────────
|
|
//
|
|
// Blank white minicards — the handle icon and nothing else, no title, no members,
|
|
// no labels — appeared among the real ones for some users.
|
|
//
|
|
// A minicard renders blank when its document is in minimongo without its fields:
|
|
// `Cards.getTitle()` returns null for `title === undefined`, and every badge is
|
|
// conditional on a field that is not there either. That is not a card with an
|
|
// empty title — the schema declares `title` as `optional: true, defaultValue: ''`,
|
|
// so a card that went through it HAS the key, `''` at worst. A document without
|
|
// the key at all is a partial replication: several publications ship cards with a
|
|
// projection (`openCardData` publishes `{ _id: 1 }` as the parent of its children
|
|
// cursors, the search publications ship their own field lists), and minimongo
|
|
// merges what every live publication says about an id.
|
|
//
|
|
// Which of them produced these particular stubs is not settled — it needs the
|
|
// running board to catch — so this is a guard at the point of drawing rather than
|
|
// a fix at the source: a document that does not carry the field the minicard is
|
|
// built around is not drawn. It cannot hide a real card, and when the full
|
|
// document arrives the card appears, which is what the blank box was standing in
|
|
// for anyway.
|
|
function renderableCardsSelector(selector) {
|
|
const sel = selector || {};
|
|
const requireTitle = { title: { $exists: true } };
|
|
|
|
// Merging at the top level keeps the selector flat (the shape the rest of the
|
|
// card path expects); only fall back to `$and` if something already speaks for
|
|
// `title`, so its meaning is never silently replaced.
|
|
if (Object.prototype.hasOwnProperty.call(sel, 'title')) {
|
|
return { $and: [sel, requireTitle] };
|
|
}
|
|
return { ...sel, ...requireTitle };
|
|
}
|
|
|
|
export { shouldShowLoadMoreSpinner, renderableCardsSelector };
|