Skip to content

Feat/real time dashboard#2186

Open
Naveen-Boddepalli wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
Naveen-Boddepalli:feat/real-time-dashboard
Open

Feat/real time dashboard#2186
Naveen-Boddepalli wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
Naveen-Boddepalli:feat/real-time-dashboard

Conversation

@Naveen-Boddepalli
Copy link
Copy Markdown

@Naveen-Boddepalli Naveen-Boddepalli commented Jun 7, 2026

Summary

Adds Supabase Realtime subscriptions to StreakTracker, GoalTracker, and DashboardHeader so dashboard widgets update live when underlying data changes — no manual refresh required. Includes a 60-second polling fallback for when the WebSocket connection is unavailable.

Closes #2115


Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation update
  • ♻️ Refactor / code cleanup
  • 🔒 Security fix

What Changed

  • src/hooks/useRealtimeSync.ts (new) — Shared hook that opens a Supabase Realtime channel for a given table and event list, tracks connection status, and falls back to polling (fallbackPollingMs, default 60 s) on CLOSED / CHANNEL_ERROR / TIMED_OUT. Uses a singleton Supabase client per tab and an onUpdateRef pattern to avoid stale closures without recreating the channel on re-renders.
  • StreakTracker.tsx — Subscribes to streak_freezes INSERT/DELETE; triggers fetchFreeze + fetchStreak on change. Shows pulsing green Live badge next to the "Commit Streaks" header when connected.
  • GoalTracker.tsx — Subscribes to goals INSERT/UPDATE/DELETE; triggers loadGoals on change. Shows pulsing green Live badge next to the "Goals" header when connected.
  • DashboardHeader.tsx — Extracts loadSettings from a useEffect to a useCallback; subscribes to users UPDATE; shows Live badge inline with the "Synced" timestamp.

How to Test

  1. Enable Realtime for the streak_freezes, goals, and users tables in the Supabase dashboard (Database → Replication).
  2. Run pnpm dev and sign in.
  3. Open the dashboard in two browser tabs.
  4. In tab 1, apply a streak freeze — confirm the StreakTracker in tab 2 updates without a reload.
  5. In tab 1, create or delete a goal — confirm the GoalTracker in tab 2 updates without a reload.
  6. Confirm the pulsing green Live badge appears in the Goals header, Streak header, and next to the "Synced" timestamp in the dashboard header.
  7. Polling fallback: Open DevTools → Network → set throttling to Offline. Confirm the Live badge disappears and data still refreshes every 60 seconds.

Expected result: All three widgets reflect changes made in another tab within 1–2 seconds when Live. No memory leaks (subscriptions are removed on unmount via the useEffect cleanup).


Screenshots

Live indicator — Goals

Live indicator — Streak Tracker

Cross-tab real-time update


Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No console.log, debug code, or commented-out blocks
  • pnpm lint passes locally
  • No TypeScript errors (pnpm type-check)
  • Added or updated tests where applicable
  • Subscriptions are cleaned up on unmount (no memory leaks)
  • Graceful degradation — polling fallback works when WebSocket is unavailable

Additional Context

Required Supabase config: Realtime must be enabled for streak_freezes, goals, and users in the Supabase dashboard under Database → Replication. Without it the hook falls back to 60-second polling automatically — nothing breaks.

No breaking changes — all existing fetch logic is preserved. Realtime is additive on top of it.

Contributed under GSSoC '26.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 7, 2026

@Naveen-Boddepalli is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:docs GSSoC type bonus: documentation (+5 pts) type:feature GSSoC type bonus: new feature labels Jun 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2026

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@Priyanshu-byte-coder
Copy link
Copy Markdown
Owner

This PR has merge conflicts with main on multiple files (ssrf-protection.ts, DashboardHeader.tsx, GoalTracker.tsx, StreakTracker.tsx). Several of these fixes have been merged via dedicated PRs.

Please:

  1. Rebase on main
  2. Remove the ssrf-protection.ts changes (already merged in fix(security): resolve IPv6-mapped IPv4 bypass in SSRF protection #2176)
  3. Keep the real-time sync feature changes
git fetch origin
git rebase origin/main

@Naveen-Boddepalli Naveen-Boddepalli force-pushed the feat/real-time-dashboard branch from 3dd759a to 890e471 Compare June 8, 2026 07:05
@Naveen-Boddepalli
Copy link
Copy Markdown
Author

  • resolved the conflicts, please review them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:docs GSSoC type bonus: documentation (+5 pts) type:feature GSSoC type bonus: new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Real-time dashboard — live data updates via Supabase Realtime subscriptions without page refresh

2 participants