Skip to content

Conversation

@factory-ben
Copy link
Owner

Fixes the critical issue where archived posts reappear after hard refresh or network issues.

Root Causes Identified

  1. Race condition in loadPostStates() - Function cleared state.archivedIds before checking if Supabase query succeeded, causing all posts to show as unarchived on error
  2. localStorage contamination - Old localStorage archive data could interfere with Supabase state for logged-in users
  3. No error recovery - Silent failures meant user had no idea their archive state failed to load
  4. Premature rendering - fetchFeed() would render before archive state loaded

Changes Made

Critical Fixes

  • Atomic state updates - Build new Sets and only update state.archivedIds if Supabase query succeeds
  • Keep state on error - Don't clear existing archive state if load fails
  • Remove localStorage - All archive state now lives in Supabase only (no localStorage fallback)
  • Require authentication - Anonymous users must sign in to use archive features
  • Loading indicator - Show "Loading your archive state..." message before first render
  • Error feedback - Toast notifications when archive state fails to load

Behavioral Changes

  • Users without login are redirected to login page (no more anonymous mode)
  • Archive/unarchive operations require state.user check
  • Sign out immediately redirects to login
  • Better console logging of archive state load status

Testing

Before: Archived posts would reappear on hard refresh or if Supabase had any hiccup
After: Archive state preserved even on network errors; user notified if state fails to load

See archive-reappear-issues.md for detailed technical analysis of all issues found.

Breaking Changes

  • Anonymous users can no longer use archive features (must sign in)
  • Old localStorage archive data is cleaned up on login but not migrated

cc @bentossell

Critical fixes for archived posts showing up after refresh:

1. **loadPostStates() race condition fix**
   - Don't clear state.archivedIds on Supabase error
   - Build new state in temp sets, only update on success
   - Add toast notification on load failure
   - Keep existing state if query fails

2. **Remove localStorage for logged-in users**
   - Deleted loadLocalArchivedState() and saveLocalArchivedState()
   - All archive state now in Supabase only
   - Anonymous users must sign in to archive posts
   - Cleaned up migrateLocalStorageToSupabase (now just cleanup)

3. **Require authentication**
   - Remove startPublicApp() - redirect to login if not authenticated
   - Sign out redirects to login immediately
   - Archive/unarchive requires state.user check

4. **Better loading state**
   - render() waits for supabaseReady before showing content
   - Show 'Loading your archive state...' message
   - Warn user if archive state fails to load

5. **Improved error handling**
   - startApp() checks if supabaseReady after loadPostStates()
   - User feedback when archive operations require login
   - Better logging of archive state load success/failure

Fixes: Archived posts will no longer reappear on hard refresh or network issues
@factory-droid
Copy link
Contributor

factory-droid bot commented Dec 16, 2025

Droid finished @factory-ben's task —— View job


Code Review Complete

Reviewed the changes in PR #31 which removes anonymous/public mode and simplifies archive state management to use Supabase only. The changes look generally solid:

  • ✅ Atomic state updates in loadPostStates() prevent partial state corruption
  • ✅ Loading state guard in render() prevents showing unarchived items before state loads
  • ✅ Error handling improvements with user-visible toasts
  • ✅ Consistent authentication checks in archive functions

Left one inline comment with a clarifying question about the migration logic change.

console.error('[Migration] Error migrating localStorage to Supabase:', e);
console.error('[Cleanup] Error removing old localStorage:', e);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this cause data loss for users who had archived items in localStorage before this change is deployed? The old code would migrate localStorage archives to Supabase first, but now they're just deleted. If this is intentional to fix the "archive reappearing" bug, perhaps worth a comment explaining why migration was removed?

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.

2 participants