Files
wekan/tests/staleWhileRevalidate.test.cjs
T
Lauri Ojansivu d00dc6056b Fix the "Board not found" flicker (stale-while-revalidate for the client board cache)
The client board cache (imports/lib/dataCache.js) re-fetches its value inside a
reactive computation. When the board doc is briefly absent from minimongo (a
subscription stops and restarts, momentarily removing the doc), the empty value
was surfaced immediately, flashing the "Board not found" shell — and on WebKit
throwing a Blaze "Can't select in removed DomRange" error tearing down the card
view. It self-recovers when the doc is re-delivered, so it presents as a flicker,
reliably hit only on Firefox/WebKit timing (which is why it surfaced as
browser-specific Playwright failures in 14-voting-watchers and 24-feature-issues).

Fixed with an opt-in stale-while-revalidate mode on DataCache, enabled only for
getBoard: a transient miss over an already-cached board keeps the last value and
re-checks after a short delay, surfacing an empty result only if the board is
still gone then (a genuine deletion / access loss). First-ever loads and caches
that did not opt in are unchanged. Core decision extracted to the pure
shouldDeferCacheMiss helper with unit tests.

Also hardens the related Playwright specs: a retry in CardPage.openActionsMenu, a
longer visibility budget for the WebKit slow card-render in spec 16, and removes a
reload race in the move-list-right spec (moveListBy fires two un-awaited
updateListSort calls, so an immediate reload read a half-applied order).
2026-07-06 01:26:05 +03:00

63 lines
2.6 KiB
JavaScript

'use strict';
// Plain-Node unit test (no Meteor) for the DataCache stale-while-revalidate
// decision — the board-not-found flicker fix.
// Run: node tests/staleWhileRevalidate.test.cjs
//
// The client board cache re-fetches inside a reactive computation. When the board
// doc is briefly missing from minimongo (a subscription stop/restart momentarily
// removes it), the re-fetch returns null and the view flips to "Board not found"
// (WebKit also throws a Blaze "removed DomRange" error). shouldDeferCacheMiss
// decides when to KEEP the last value and re-check shortly instead of surfacing
// that transient miss. It must never defer a genuine first-load miss, and must
// only apply when the owning cache opted in.
const assert = require('assert');
const { shouldDeferCacheMiss } = require('../imports/lib/staleWhileRevalidate');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
const SWR = { staleWhileRevalidate: true };
const OFF = {};
const BOARD = { _id: 'b1', title: 'Board' };
// --- POSITIVE: defer a transient miss over a cached value -------------------
test('POSITIVE: defers when a cached board momentarily re-fetches as null', () => {
assert.strictEqual(shouldDeferCacheMiss(SWR, null, BOARD), true);
});
test('POSITIVE: defers for undefined too (findOne returns undefined)', () => {
assert.strictEqual(shouldDeferCacheMiss(SWR, undefined, BOARD), true);
});
// --- NEGATIVE: never hide a real value or a genuine first-load miss ---------
test('NEGATIVE: a real fetched value is never deferred', () => {
assert.strictEqual(shouldDeferCacheMiss(SWR, BOARD, BOARD), false);
assert.strictEqual(shouldDeferCacheMiss(SWR, BOARD, null), false);
});
test('NEGATIVE: first-ever load (no cached value) surfaces the miss immediately', () => {
// Nothing cached yet -> real "not found" must render promptly, not be deferred.
assert.strictEqual(shouldDeferCacheMiss(SWR, null, null), false);
assert.strictEqual(shouldDeferCacheMiss(SWR, null, undefined), false);
});
test('NEGATIVE: caches that did NOT opt in are unaffected (default behaviour)', () => {
// Lists/cards/etc. keep the original immediate-write semantics.
assert.strictEqual(shouldDeferCacheMiss(OFF, null, BOARD), false);
assert.strictEqual(shouldDeferCacheMiss(undefined, null, BOARD), false);
});
test('NEGATIVE: a falsy-but-present cached value (0 / "") is still preserved', () => {
// Guard uses null/undefined checks, not truthiness, so 0 or "" count as cached.
assert.strictEqual(shouldDeferCacheMiss(SWR, null, 0), true);
assert.strictEqual(shouldDeferCacheMiss(SWR, null, ''), true);
});
console.log(`\n${passed} passing`);