From f96c1b33c052a2e6317ab422ef83f0009fed2b27 Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Sat, 6 Jun 2026 10:05:24 +0000 Subject: [PATCH] Fix referral list race condition causing entries to flash and disappear Two concurrent loadAdminReferrals() calls shared the same DOM container, so whichever fetch resolved last would overwrite the other's result. Added a request ID counter (_refListReqId) so stale responses are discarded rather than applied. Co-Authored-By: Claude Sonnet 4.6 --- admin/index.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/admin/index.php b/admin/index.php index 50dfed3..66ea8c2 100644 --- a/admin/index.php +++ b/admin/index.php @@ -2480,6 +2480,7 @@ async function submitPayout(){ // ─── REFERRAL MANAGEMENT ────────────────────────────────── let _refTiers = []; +let _refListReqId = 0; function showRefSection(section) { document.getElementById('ref-admin-list').style.display = section==='list'?'block':'none'; @@ -2490,6 +2491,7 @@ function showRefSection(section) { } async function loadAdminReferrals(status, btn) { + const reqId = ++_refListReqId; document.getElementById('ref-admin-list').style.display='block'; document.getElementById('ref-tiers-section').style.display='none'; document.getElementById('ref-shares-section').style.display='none'; @@ -2497,6 +2499,7 @@ async function loadAdminReferrals(status, btn) { const el = document.getElementById('ref-admin-list'); el.innerHTML = '
Loading...
'; const d = await fetch('/api/referrals.php?action=admin_list&status='+status).then(r=>r.json()); + if (reqId !== _refListReqId) return; // discard stale response if (!d.success||!d.referrals.length) { el.innerHTML='
No '+status+' referrals.
'; return; } el.innerHTML = d.referrals.map(r => buildRefCard(r, status)).join(''); } @@ -2525,7 +2528,9 @@ async function resolveReferral(id, status) { }).then(r=>r.json()); if (d.success) { toast(status==='verified' ? 'Verified! '+d.tokens_awarded+' tokens awarded' : 'Denied', status==='verified'?'ok':'err'); - loadAdminReferrals('pending', document.querySelector('#section-referrals .ftab')); + // Reload the pending tab (items resolved out of pending); active tab indicator stays correct + const pendingBtn = document.querySelector('#section-referrals .ftab'); + loadAdminReferrals('pending', pendingBtn); loadStats(); } else toast(d.error||'Error','err'); }