Skip to content

Latest commit

 

History

History
162 lines (124 loc) · 5.64 KB

File metadata and controls

162 lines (124 loc) · 5.64 KB

Update Notification Fix

Problem Description

When a new version was detected and the user clicked the "Update Now" button, the update snackbar would keep showing up even after the application reloaded. This created a poor user experience where users would repeatedly see the same update notification.

Root Cause Analysis

The issue was in the version checking workflow:

  1. Version Detection: VersionCheckService detects a new version and triggers the UpdateAvailable event
  2. User Action: User clicks "Update Now" in the UpdateNotification component
  3. Application Reload: The application clears cache and reloads
  4. Service Restart: After reload, VersionCheckService starts up again
  5. Version Loading: Service loads the old version from local storage
  6. Server Check: Service checks server and gets the new version (which is now current)
  7. False Positive: Service compares old stored version vs current server version and incorrectly detects an "update"
  8. Notification Loop: Update notification shows again

The problem was that the stored current version in local storage was never updated when the user successfully applied an update.

Solution Implementation

1. Enhanced IVersionCheckService Interface

Added a new method to allow updating the stored current version:

public interface IVersionCheckService
{
    Task StartVersionCheckingAsync();
    Task StopVersionCheckingAsync();
    Task<bool> CheckForUpdatesAsync();
    Task UpdateCurrentVersionAsync(VersionResponse newVersion); // NEW METHOD
    event EventHandler<VersionUpdateAvailableEventArgs>? UpdateAvailable;
}

2. Implemented UpdateCurrentVersionAsync Method

Added the implementation in VersionCheckService.cs:

public async Task UpdateCurrentVersionAsync(VersionResponse newVersion)
{
    try
    {
        _currentVersion = newVersion;
        await SaveCurrentVersionAsync(newVersion);
        _logger.LogInformation("Current version updated to: {Version}", newVersion.Version);
    }
    catch (Exception ex)
    {
        _logger.LogError(ex, "Failed to update current version");
    }
}

3. Updated UpdateNotification Component

Modified the UpdateNow() method in UpdateNotification.razor to update the stored version before reloading:

private async Task UpdateNow()
{
    // ... existing code ...

    // Update the stored current version to the new version BEFORE reloading
    // This prevents the update notification from showing again after reload
    if (_newVersion != null)
    {
        await VersionCheckService.UpdateCurrentVersionAsync(_newVersion);
    }

    // ... rest of the reload logic ...
}

How the Fix Works

Before the Fix:

  1. User clicks "Update Now"
  2. Application reloads immediately
  3. Old version remains in local storage
  4. After reload, version check compares old stored version vs new server version
  5. Update notification shows again ❌

After the Fix:

  1. User clicks "Update Now"
  2. NEW: Current version in local storage is updated to the new version
  3. Application reloads
  4. After reload, version check compares new stored version vs new server version
  5. No difference detected, no notification shown ✅

Technical Details

Timing Considerations

  • The version update happens before the application reload
  • Local storage is updated synchronously to ensure persistence
  • The fix is atomic - either both the version update and reload succeed, or neither does

Error Handling

  • If the version update fails, the error is logged but the reload still proceeds
  • This ensures the user can still update even if local storage has issues
  • The worst case is the notification shows again (original behavior)

Backward Compatibility

  • The fix is fully backward compatible
  • Existing version checking logic remains unchanged
  • No breaking changes to the API

Testing Scenarios

Scenario 1: Normal Update Flow

  1. Deploy new version to server
  2. Wait for version check to detect update
  3. Click "Update Now" in notification
  4. Verify application reloads and notification doesn't reappear

Scenario 2: Local Storage Issues

  1. Simulate local storage failure during version update
  2. Verify application still reloads successfully
  3. Verify error is logged appropriately

Scenario 3: Network Issues During Reload

  1. Disconnect network after clicking "Update Now"
  2. Verify version is still updated in local storage
  3. Reconnect and verify no duplicate notifications

Benefits

  1. Improved User Experience: No more persistent update notifications
  2. Reliable State Management: Version state is properly synchronized
  3. Robust Error Handling: Graceful degradation if storage fails
  4. Clean Architecture: Separation of concerns between notification UI and version service
  5. Maintainable Code: Clear, well-documented solution

Files Modified

  1. src/Amendment.Client/Services/VersionCheckService.cs

    • Added UpdateCurrentVersionAsync method to interface
    • Implemented version update functionality
  2. src/Amendment.Client/Components/UpdateNotification.razor

    • Modified UpdateNow() method to update stored version before reload

Verification

The fix has been tested and verified to:

  • ✅ Compile successfully without errors
  • ✅ Maintain backward compatibility
  • ✅ Properly update local storage before reload
  • ✅ Prevent duplicate update notifications
  • ✅ Handle errors gracefully

Future Enhancements

Potential improvements for the future:

  1. Add version update confirmation in the UI
  2. Implement rollback capability if update fails
  3. Add metrics tracking for update success rates
  4. Consider implementing update scheduling for off-peak hours