Skip to content

Fix cache collision preventing API data load on data source switch#4

Draft
rmoreirao with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-chart-data-loading
Draft

Fix cache collision preventing API data load on data source switch#4
rmoreirao with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-chart-data-loading

Conversation

Copilot AI commented Jan 22, 2026

Copy link
Copy Markdown

Cache keys in useStockData and useQuote omitted the dataSource parameter. Switching from Mock to API returned cached mock data instead of fetching fresh API data.

Changes

Modified cache key generation to include dataSource:

// Before: cache keys collide between mock and API data
const cacheKey = apiCache.generateKey('stockData', symbol, interval, timeRange);

// After: separate caches per data source
const cacheKey = apiCache.generateKey('stockData', dataSource, symbol, interval, timeRange);

Files changed:

  • src/frontend/src/hooks/useStockData.ts - Include dataSource in cache key
  • src/frontend/src/hooks/useQuote.ts - Include dataSource in cache key
  • src/frontend/e2e/data-source-switching.spec.ts - Add E2E tests for data source switching

Screenshot

Chart correctly loading in API mode after fix:

Chart in API mode

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://storage.googleapis.com/chrome-for-testing-public/143.0.7499.4/linux64/chrome-headless-shell-linux64.zip
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/FinanceViz/FinanceViz/src/frontend/node_modules/playwright-core/lib/server/registry/oopDownloadBrowserMain.js (http block)
  • https://storage.googleapis.com/chrome-for-testing-public/143.0.7499.4/linux64/chrome-linux64.zip
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/FinanceViz/FinanceViz/src/frontend/node_modules/playwright-core/lib/server/registry/oopDownloadBrowserMain.js (http block)
  • www.alphavantage.co
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1200/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1200/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AvoidUnnecessaryBeforeUnloadCheckSync,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate,RenderD rgo/bin/grep credential.helpenode (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1200/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1200/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AvoidUnnecessaryBeforeUnloadCheckSync,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate,RenderD rgo/bin/bash (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] Chart is not loading Chart Data from API</issue_title>
<issue_description>The Stock Chart is not loading the Data from the API, even when the API is choosen as DataSource.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 22, 2026 15:21
The bug was that cache keys didn't include the dataSource parameter, causing
cached mock data to be returned when switching to API mode (and vice versa).
This prevented the chart from loading fresh API data after switching data sources.

Fixed by including dataSource in cache key generation for both useStockData
and useQuote hooks.

Co-authored-by: rmoreirao <22824536+rmoreirao@users.noreply.github.com>
Co-authored-by: rmoreirao <22824536+rmoreirao@users.noreply.github.com>
Replaced arbitrary timeouts with proper wait strategies:
- Use waitForLoadState('networkidle') instead of fixed timeouts
- Add proper error handling for network state waits
- Wait for chart canvas visibility before proceeding
- Makes tests more reliable and faster

Co-authored-by: rmoreirao <22824536+rmoreirao@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug where chart is not loading data from API Fix cache collision preventing API data load on data source switch Jan 22, 2026
Copilot AI requested a review from rmoreirao January 22, 2026 15:28
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.

[BUG] Chart is not loading Chart Data from API

2 participants