Fix: Project dashboard not updating emissions data#1169
Open
Mounesh-13 wants to merge 1 commit intomlco2:masterfrom
Open
Fix: Project dashboard not updating emissions data#1169Mounesh-13 wants to merge 1 commit intomlco2:masterfrom
Mounesh-13 wants to merge 1 commit intomlco2:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.