From 096c12ab462692edaf6097cdce82a7e9a634dc62 Mon Sep 17 00:00:00 2001 From: martbost Date: Fri, 18 Sep 2026 11:30:30 -0500 Subject: [PATCH] Fix scope bug that dropped the referral from the join button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The placement flag was declared inside the invited-visitor branch but read further down when building the join button href, so it threw a ReferenceError there. The display was right — the page named the inviter correctly — but the button fell back to a bare /join-now, which is the one place that actually matters. Caught by walking the live paths rather than trusting the earlier pass. Co-Authored-By: Claude Opus 5 (1M context) --- public/start.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/public/start.js b/public/start.js index 62b9a4e..3bdb2d1 100644 --- a/public/start.js +++ b/public/start.js @@ -13,9 +13,21 @@ function invitedBy(){ }catch(e){} return null; } +function placementChoice(){ + try{ + const q=new URLSearchParams(location.search).get('direct'); + if(q==='1'||q==='0')return q; + const m=document.cookie.match(/(?:^|;\s*)rmc_direct=([01])/); + if(m)return m[1]; + }catch(e){} + return null; +} async function load(){ try{ const ref=invitedBy(); + // an explicit ?direct=1/0 from the invite link wins over the position's default, and it + // has to be in scope for the join button further down — not just the display block + const dq=placementChoice(); const [cr,sr]=await Promise.all([ fetch('/api/public/config'), fetch(ref?('/api/public/member?id='+encodeURIComponent(ref)):'/api/public/current-sponsor') @@ -26,10 +38,6 @@ async function load(){ // Route exactly the way that member's own invite page would: their moving link sends // the join to the next position in their leg, unless their position is set to take // direct placements. Same rules, so the two pages can never disagree. - // an explicit ?direct=1/0 from the invite link wins over the position's default - const dq=(function(){try{const q=new URLSearchParams(location.search).get('direct'); - if(q==='1'||q==='0')return q; - const m=document.cookie.match(/(?:^|;\s*)rmc_direct=([01])/);return m?m[1]:null;}catch(e){return null}})(); const goDirect=dq==='1'||(dq!=='0'&&(s.directDefault||!s.joinTarget)); const t=goDirect?{id:s.id,referralUrl:s.referralUrl,directCount:s.directCount}:s.joinTarget; currentSponsor={id:t.id,name:null,directs:(t.directCount!==undefined?t.directCount:0),goal:2,referralUrl:t.referralUrl};