Skip to content

Replace mock notifications with real-time Firestore listener (fixes #639)#644

Open
Priyanka0205-CSE wants to merge 2 commits into
indresh404:mainfrom
Priyanka0205-CSE:fix/notification-listener-cleanup-639
Open

Replace mock notifications with real-time Firestore listener (fixes #639)#644
Priyanka0205-CSE wants to merge 2 commits into
indresh404:mainfrom
Priyanka0205-CSE:fix/notification-listener-cleanup-639

Conversation

@Priyanka0205-CSE

Copy link
Copy Markdown
Contributor

Summary

Closes #639

While investigating this issue, I found that NotificationBell.jsx doesn't exist as a separate component, and the notification bell in Navbar.jsx was rendering static mockNotifications data with no Firestore listener at all — so the originally-described cleanup bug didn't apply to the current codebase.

I repurposed the issue to implement the real thing: a live, Firestore-backed notification system with correct listener lifecycle handling built in from the start.

Changes

  • Removed mockNotifications import and static data usage
  • Added a real-time onSnapshot listener on users/{uid}/notifications, ordered by createdAt
  • Listener has a stable [user?.uid] dependency array and is properly unsubscribed on unmount/auth change
  • markAllAsRead, deleteNotification, and clearAllNotifications now write directly to Firestore instead of only updating local state

Testing

  • Verified npm run dev builds cleanly with no console errors from the new code
  • Confirmed the listener safely no-ops when user is null (logged out / Firebase not configured locally) — falls into the early-return branch and clears local state
  • Full end-to-end testing of live updates wasn't possible locally since Firebase env vars aren't configured in my dev environment (noted separately)

Notes

  • This PR wires up the listener and read/write actions against a users/{uid}/notifications subcollection. Populating that collection (e.g. triggering a notification doc on follow/comment events) is out of scope here and could be a follow-up.

@vercel

vercel Bot commented Jul 20, 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 Jul 20, 2026 6:13am

@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) nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review labels Jul 20, 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) 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]: Firestore onSnapshot listener is never unsubscribed on unmount, causing duplicate listeners and stale toast triggers on repeated navigation

1 participant