fix(wb): latest lookup wins the worked-before panel

Two lookups race when a second callsign is typed before the first answered,
and the slow one landed last: the grid showed the previous call's QSOs under
the new call's name — LU5AVM's contact filed under LW8ETV, screenshot in
hand. A request token now discards any response that is not the newest.
This commit is contained in:
2026-08-30 11:26:47 +02:00
parent 8e7ecc3d51
commit 7b15b534cd
2 changed files with 13 additions and 3 deletions
+9 -1
View File
@@ -4615,10 +4615,17 @@ export default function App() {
return () => { dead = true; };
}, [selQso, callsign]);
const wbTokenRef = useRef(0);
async function runWorkedBefore(call: string, dxccHint: number = 0) {
// Latest-wins: two lookups race when the operator types a second call
// before the first answered, and the SLOW one used to land last — the
// grid then showed the previous call's QSOs under the new call's name
// (LU5AVM's contact filed under LW8ETV, screenshot in hand).
const token = ++wbTokenRef.current;
setWbBusy(true);
try {
const w = await WorkedBefore(call, dxccHint);
if (token !== wbTokenRef.current) return; // a newer lookup owns the panel
setWb(w);
// Mirrored synchronously rather than through the effect above: a backfill
// parked by the lookup has to read this on the very next line, not a
@@ -4633,10 +4640,11 @@ export default function App() {
fillFromLastQso(p.r, call);
}
} catch {
if (token !== wbTokenRef.current) return;
setWb(null);
wbRef.current = null;
wbCallRef.current = '';
} finally { setWbBusy(false); }
} finally { if (token === wbTokenRef.current) setWbBusy(false); }
}
// fillFromLastQso enriches the entry from the LAST QSO we logged with this call
// when the live lookup came up short — the callsign isn't on QRZ/HamQTH, or no