Skip to content

Fix tab switching with caching to avoid redundant API calls#43

Open
Zayed-Ahmed-dev wants to merge 1 commit into
chaoss:mainfrom
Zayed-Ahmed-dev:fix/tab-caching
Open

Fix tab switching with caching to avoid redundant API calls#43
Zayed-Ahmed-dev wants to merge 1 commit into
chaoss:mainfrom
Zayed-Ahmed-dev:fix/tab-caching

Conversation

@Zayed-Ahmed-dev
Copy link
Copy Markdown

Description

This PR fixes an issue where switching between different models (Aurora, ST Description, ST URL) was causing repeated API calls and loss of previously fetched results.


Problem

  • Every time a user switched tabs, a new API request was sent
  • Previously fetched results were not preserved
  • This led to:
    • Slower performance
    • Unnecessary backend load
    • Poor user experience

Solution

  • Added a per-model caching system using React state
  • Stored results for each model after the first API call
  • When switching tabs:
    • If data already exists → use cached results
    • If not → fetch from API and store it

Improvements

  • Avoids redundant API calls
  • Faster tab switching (instant if cached)
  • Preserves results for each model
  • Edited results are saved per tab
  • No breaking changes to existing functionality

Changes Made

  • Added modelResultsCache state to store results per model
  • Updated handleTabChange:
    • Checks cache before making API call
    • Stores new responses in cache
  • Updated saveEditedResults:
    • Syncs edited results with cache
  • Added useEffect:
    • Stores initial results in cache
  • Fixed loading state handling for cached data

Demo (Before vs After)

beforeCaching.mp4
afterCaching.mp4

Result

  • Tab switching is now smooth and instant after first load
  • No repeated API calls for the same model
  • Improved performance and user experience

Signed-off-by: zayed <zayedahmed745@gmail.com>
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