Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 14, 2025

Problem

Pages with rid query parameter (e.g., /guidelines?rid=abc123) were returning blank content with HTTP 200 status, while the same pages without the parameter worked correctly.

Root Cause

The ReferralMiddleware was processing referral tracking but failing to continue the request pipeline when a rid parameter was present. The middleware was missing the critical await _Next(context); call after referral processing, causing the request to terminate early.

Before (Broken):

public async Task InvokeAsync(HttpContext context, IReferralService referralService, UserManager<EssentialCSharpWebUser> userManager)
{
    string? referralId = query["rid"];
    if (string.IsNullOrWhiteSpace(referralId))
    {
        await _Next(context);  // ✓ Continues pipeline when NO rid
        return;
    }
    
    // Process referral tracking
    referralService.TrackReferralAsync(referralId, claimsUser);
    
    // ❌ MISSING: await _Next(context);
    // Pipeline stops here when rid exists!
}

After (Fixed):

public async Task InvokeAsync(HttpContext context, IReferralService referralService, UserManager<EssentialCSharpWebUser> userManager)
{
    string? referralId = query["rid"];
    if (string.IsNullOrWhiteSpace(referralId))
    {
        await _Next(context);
        return;
    }
    
    try
    {
        // Process referral tracking
        referralService.TrackReferralAsync(referralId, claimsUser);
    }
    catch (Exception ex)
    {
        _logger.LogError(ex, "Failed to track referral ID {ReferralId}", referralId);
    }
    
    // ✅ FIXED: Always continue the pipeline
    await _Next(context);
}

Changes Made

  1. Critical Fix: Added missing await _Next(context); call after referral processing
  2. Error Resilience: Added try-catch around referral tracking to prevent exceptions from breaking page rendering
  3. Logging Enhancement: Added structured error logging for debugging referral tracking issues
  4. Test Coverage: Added comprehensive tests to verify the fix works for all scenarios

Verification

/guidelines?rid=abc123 now renders content correctly
/about?rid=user-ref now renders content correctly
✅ Referral tracking functionality preserved
✅ Error scenarios handled gracefully
✅ Backward compatibility maintained

Test Cases Added

  • Pages with valid rid parameters return content
  • Pages with empty/whitespace rid parameters work correctly
  • Pages with non-rid parameters continue to work
  • Error scenarios are logged but don't break page rendering

Fixes #756.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Non-content pages are returned blank with referrid query parameter Fix ReferralMiddleware causing blank pages with rid query parameter Jul 14, 2025
Copilot AI requested a review from BenjaminMichaelis July 14, 2025 17:52
Copilot finished work on behalf of BenjaminMichaelis July 14, 2025 17:52
@BenjaminMichaelis BenjaminMichaelis changed the title Fix ReferralMiddleware causing blank pages with rid query parameter fix: ReferralMiddleware causing blank pages with rid query parameter Jul 14, 2025
@BenjaminMichaelis BenjaminMichaelis marked this pull request as ready for review July 14, 2025 22:10
Copilot AI requested a review from Keboo July 14, 2025 22:24
Copilot finished work on behalf of Keboo July 14, 2025 22:24
@BenjaminMichaelis BenjaminMichaelis enabled auto-merge (squash) July 14, 2025 22:32
@BenjaminMichaelis BenjaminMichaelis merged commit 52f77b3 into main Jul 14, 2025
5 checks passed
@BenjaminMichaelis BenjaminMichaelis deleted the copilot/fix-756 branch July 14, 2025 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-content pages are returned blank with referrid query parameter

3 participants