Skip to content

fix: sync profile avatar across open tabs via localStorage#557

Open
saurabhhhcodes wants to merge 1 commit into
indresh404:mainfrom
saurabhhhcodes:fix/cross-tab-avatar-sync
Open

fix: sync profile avatar across open tabs via localStorage#557
saurabhhhcodes wants to merge 1 commit into
indresh404:mainfrom
saurabhhhcodes:fix/cross-tab-avatar-sync

Conversation

@saurabhhhcodes

Copy link
Copy Markdown

Description

Fixes #550

The profile avatar doesn't update in other open tabs after being changed in settings.

Root Cause

The existing onSnapshot listener on the Firestore user document should handle cross-tab sync, but Firestore's local IndexedDB cache (shared across tabs in the same origin) can suppress the real-time callback when the cache is updated from another tab's write.

Fix

  • Profile.jsx: After updating the avatar in Firestore, write the new URL to localStorage using a namespaced key (rh_avatar_${uid})
  • AuthContext.jsx: Listen for the window storage event. When a cross-tab avatar change is detected, update userData state immediately

This pattern uses the browser's built-in cross-tab communication mechanism (storage events fire automatically in other tabs when localStorage changes) without requiring any external API.

Testing

  1. Open two RankerHub tabs
  2. In Tab A, go to Profile settings and update the avatar
  3. Switch to Tab B — the avatar should update within ~100ms without manual refresh

Use the storage event to propagate avatar URL changes to all open tabs.
When a user updates their avatar in Profile settings, the new URL is
written to localStorage. Other tabs detect the change via the window
'storage' event and update userData state immediately.

Closes indresh404#550
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ranker-hub Ready Ready Preview, Comment Jun 16, 2026 11:59am

@github-actions github-actions Bot added backend Backend/Firebase related changes bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request frontend Frontend related changes (HTML/CSS/JS/React) gssoc GirlScript Summer of Code gssoc26 GirlScript Summer of Code 2026 nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review labels Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend/Firebase related changes bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request frontend Frontend related changes (HTML/CSS/JS/React) gssoc GirlScript Summer of Code gssoc26 GirlScript Summer of Code 2026 nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Profile avatar doesn't update across tabs after changing it in settings

1 participant