Skip to content

Fix: Project dashboard not updating emissions data#1169

Open
Mounesh-13 wants to merge 1 commit intomlco2:masterfrom
Mounesh-13:fix/project-dashboard-swr
Open

Fix: Project dashboard not updating emissions data#1169
Mounesh-13 wants to merge 1 commit intomlco2:masterfrom
Mounesh-13:fix/project-dashboard-swr

Conversation

@Mounesh-13
Copy link
Copy Markdown

Problem
The Project dashboard does not update emissions data dynamically, while the Home dashboard reflects updates correctly.

Root Cause
The Home tab uses useSWR, which provides automatic polling and revalidation.
The Project tab relied on useEffect, resulting in stale data unless the page was manually refreshed.

Solution

Replaced useEffect-based data fetching with useSWR
Added refreshInterval (60s) for automatic updates
Used dynamic SWR keys (projectId + date range) to ensure proper re-fetching
Kept aggregation logic in the frontend using useMemo for performance

Improvements

Added null-safe reducers (?? 0) to prevent NaN issues from malformed API data
Introduced a user-facing error state for failed data fetching
Aligned Project dashboard behavior with Home dashboard for consistency

Testing

Verified automatic refresh (updates within 60 seconds)
Verified date range filter triggers re-fetch
Verified data updates after switching browser tabs (focus revalidation)
Verified correct behavior for empty projects (no NaN values)
Confirmed no console errors or UI regressions

This change ensures the Project dashboard stays in sync with real-time emissions data and improves overall reliability.

@Mounesh-13 Mounesh-13 requested a review from a team as a code owner April 28, 2026 16:37
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.

1 participant