refactor(web): migrate to SWR for data fetching#585
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates the web app’s config/providers data fetching to SWR to ensure requests like /api/config are deduplicated and cached across multiple consumers (addressing duplicate fetches noted in #474).
Changes:
- Add SWR and configure global SWR defaults in the web app entrypoint.
- Refactor
useNetworkConfiganduseProvidersListto use SWR with sharedfetcher+ cache keys (apiPaths). - Update web tests to mock SWR-backed hooks and isolate SWR cache per test where needed.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds swr dependency and updates lockfile snapshot entries. |
| apps/web/package.json | Declares swr as a web dependency. |
| apps/web/src/main.tsx | Wraps the app in SWRConfig to set global SWR options. |
| apps/web/src/api/client.ts | Introduces a generic SWR fetcher and centralized apiPaths key builders. |
| apps/web/src/hooks/useProvidersList.ts | Migrates providers list fetching to SWR. |
| apps/web/src/hooks/useNetworkConfig.ts | Migrates /api/config fetching to SWR for shared caching. |
| apps/web/src/pages/Landing.test.tsx | Mocks useNetworkConfig to avoid SWR-backed network/config behavior in this test. |
| apps/web/src/components/shared/Network/NetworkSwitcher.test.tsx | Wraps renders with SWRConfig using a fresh cache per test. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
|
@silent-cipher : I wanted to check: is there any issues with merging in this work before GA? I want to make sure we don't impact GA with adding multiple-network support to dealbot. We absolutely should get that added to dealbot, but I'd preferr to live with the status quo to keep us stable at the moment. |
|
No, I don't see any issues with merging this before GA. Agreed that stability is what we should optimize for right now. |
closes #474