Remove SWR fully and standardize web/service fetchers #21310

Closed
opened 2026-02-21 20:11:55 -05:00 by yindo · 0 comments
Owner

Originally created by @lyzno1 on GitHub (Dec 26, 2025).

Originally assigned to: @lyzno1 on GitHub.

Context

Most data fetching has migrated to TanStack Query. Remaining SWR artifacts are limited but still present, and the final SWR usage in chat hooks was just migrated but needs to be explicitly captured in this work stream:

  • Chat hooks migration (recent):
    • web/app/components/base/chat/embedded-chatbot/hooks.tsx
    • web/app/components/base/chat/chat-with-history/hooks.tsx
    • share query hooks/keys added in web/service/use-share.ts
    • These are the last chat-module SWR usages and should be part of the overall SWR removal narrative and verification.
  • SWR initializer: web/app/components/swr-initializer.tsx and its usage in web/app/(commonLayout)/layout.tsx and web/app/account/(commonLayout)/layout.tsx
  • SWR Fetcher type usage in web/service/annotation.ts and web/service/plugins.ts
  • swr dependency in web/package.json
  • References in tooling/docs/comments: .claude/skills/component-refactoring/SKILL.md, web/scripts/* (component analyzer/refactor scripts), web/service/apps.ts comment, web/knip.config.ts ignore entry

Goal

Fully drop SWR from the web app and standardize service fetchers on explicit typed functions (e.g. export const login = ({ url, body }: { url: string, body: Record<string, any> }): Promise<LoginResponse> => post(...)) instead of SWR Fetcher types. Also ensure the last chat hooks migration is documented/verified as part of the SWR removal.

Tasks

  • Document and verify the chat hooks migration is complete and aligns with React Query conventions:
    • embedded-chatbot/hooks.tsx and chat-with-history/hooks.tsx use React Query hooks and proper invalidation.
    • web/service/use-share.ts provides query keys/hooks used by chat modules.
    • Ensure focus/reconnect refetch behavior matches previous SWR settings.
  • Replace SWR Fetcher type usages with explicit typed functions:
    • web/service/annotation.ts: annotationBatchImport, checkAnnotationBatchImportProgress
    • web/service/plugins.ts: fetchMarketplaceCollections, fetchMarketplaceCollectionPlugins
    • Confirm no other SWR Fetcher types remain.
  • Remove SWR initializer:
    • Delete web/app/components/swr-initializer.tsx.
    • Remove SwrInitializer/SwrInitor usage from layouts and adjust the provider tree if needed.
    • Update web/knip.config.ts ignore list.
  • Drop SWR dependency and clean up references:
    • Remove swr from web/package.json and lockfile.
    • Update scripts that mention SWR (web/scripts/analyze-component.js, web/scripts/refactor-component.js, web/scripts/component-analyzer.js) to align with React Query only.
    • Update docs/comments mentioning SWR migration (e.g. .claude/skills/component-refactoring/SKILL.md, web/service/apps.ts comment).
    • Sweep for residual useSWR, SWRConfig, or swr references.

Acceptance criteria

  • rg "useSWR|SWRConfig|Fetcher from 'swr'|swr-initializer" web returns zero.
  • pnpm lint:fix, pnpm type-check:tsgo, pnpm test pass.
  • App loads without an SWR provider and uses React Query hooks for data fetching.
Originally created by @lyzno1 on GitHub (Dec 26, 2025). Originally assigned to: @lyzno1 on GitHub. ## Context Most data fetching has migrated to TanStack Query. Remaining SWR artifacts are limited but still present, and the **final SWR usage in chat hooks was just migrated** but needs to be explicitly captured in this work stream: - **Chat hooks migration (recent):** - `web/app/components/base/chat/embedded-chatbot/hooks.tsx` - `web/app/components/base/chat/chat-with-history/hooks.tsx` - share query hooks/keys added in `web/service/use-share.ts` - These are the last chat-module SWR usages and should be part of the overall SWR removal narrative and verification. - SWR initializer: `web/app/components/swr-initializer.tsx` and its usage in `web/app/(commonLayout)/layout.tsx` and `web/app/account/(commonLayout)/layout.tsx` - SWR `Fetcher` type usage in `web/service/annotation.ts` and `web/service/plugins.ts` - `swr` dependency in `web/package.json` - References in tooling/docs/comments: `.claude/skills/component-refactoring/SKILL.md`, `web/scripts/*` (component analyzer/refactor scripts), `web/service/apps.ts` comment, `web/knip.config.ts` ignore entry ## Goal Fully drop SWR from the web app and standardize service fetchers on explicit typed functions (e.g. `export const login = ({ url, body }: { url: string, body: Record<string, any> }): Promise<LoginResponse> => post(...)`) instead of SWR `Fetcher` types. Also ensure the last chat hooks migration is documented/verified as part of the SWR removal. ## Tasks - Document and verify the **chat hooks migration** is complete and aligns with React Query conventions: - `embedded-chatbot/hooks.tsx` and `chat-with-history/hooks.tsx` use React Query hooks and proper invalidation. - `web/service/use-share.ts` provides query keys/hooks used by chat modules. - Ensure focus/reconnect refetch behavior matches previous SWR settings. - Replace SWR `Fetcher` type usages with explicit typed functions: - `web/service/annotation.ts`: `annotationBatchImport`, `checkAnnotationBatchImportProgress` - `web/service/plugins.ts`: `fetchMarketplaceCollections`, `fetchMarketplaceCollectionPlugins` - Confirm no other SWR `Fetcher` types remain. - Remove SWR initializer: - Delete `web/app/components/swr-initializer.tsx`. - Remove `SwrInitializer`/`SwrInitor` usage from layouts and adjust the provider tree if needed. - Update `web/knip.config.ts` ignore list. - Drop SWR dependency and clean up references: - Remove `swr` from `web/package.json` and lockfile. - Update scripts that mention SWR (`web/scripts/analyze-component.js`, `web/scripts/refactor-component.js`, `web/scripts/component-analyzer.js`) to align with React Query only. - Update docs/comments mentioning SWR migration (e.g. `.claude/skills/component-refactoring/SKILL.md`, `web/service/apps.ts` comment). - Sweep for residual `useSWR`, `SWRConfig`, or `swr` references. ## Acceptance criteria - `rg "useSWR|SWRConfig|Fetcher from 'swr'|swr-initializer" web` returns zero. - `pnpm lint:fix`, `pnpm type-check:tsgo`, `pnpm test` pass. - App loads without an SWR provider and uses React Query hooks for data fetching.
yindo added the 💪 enhancement label 2026-02-21 20:11:55 -05:00
yindo closed this issue 2026-02-21 20:11:55 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21310