feat(swr): SWR integration#1723
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/json-schema
@orpc/nest
@orpc/next
@orpc/openapi
@orpc/opentelemetry
@orpc/pinia-colada
@orpc/pino
@orpc/publisher
@orpc/ratelimit
@orpc/server
@orpc/shared
@orpc/swr
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/zod
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
ℹ️ One minor consistency note.
Reviewed changes — adds @orpc/react-swr, the SWR integration for oRPC v2, following the same SharedUtils → ProcedureUtils → createRouterUtils architecture as @orpc/tanstack-query and @orpc/pinia-colada.
- New
@orpc/react-swrpackage — provides.key,.fetcher,.mutator,.subscriber,.liveSubscriber,.call, and.matcherforuseSWR,useSWRInfinite,useSWRMutation, anduseSWRSubscription - Key generation and matcher —
generateOperationKeywith optionalprefixfor avoiding key conflicts;SharedUtils.matcherwithpartial/exactstrategies powered byisSubsetOf - Operation context —
OPERATION_CONTEXT_SYMBOLis injected into client context on every call, allowing links to adjust HTTP methods or other behavior per operation type - Subscription support —
.subscriberand.liveSubscriberconsumeAsyncIteratorObjectoutput withrefetchModeandmaxChunksoptions - Documentation — new
apps/content/docs/integrations/react-swr.mdpage with setup, data fetching, infinite queries, subscriptions, mutations, manual revalidation, and operation context examples - README sync — the integration is added to 24 README files across the monorepo
ℹ️ Nitpicks
- Root
package.jsondevDependenciesis missing@orpc/react-swr—@orpc/tanstack-queryis listed there; adding it keeps the monorepo scaffolding consistent.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — renames the package from @orpc/react-swr to @orpc/swr across the monorepo, and bumps the SWR peer dependency.
- Package rename —
@orpc/react-swr→@orpc/swrwith directorypackages/react-swr/→packages/swr/; all source files, tests, READMEs (24+), docs page, VitePress config,vitest.config.ts, andpnpm-lock.yamlconsistently updated - SWR version bump — peer dependency raised from
>=2.3.6to>=2.4.2, dev dependency from^2.4.1to^2.4.2 - Docs page —
apps/content/docs/integrations/react-swr.mdrenamed toswr.mdwith all import paths, install commands, and JSDoc@seeURLs updated to the new package name
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — adds refetchMode: 'replace' to the subscriber, which buffers stream events internally and atomically replaces cached data after the stream completes.
- Added
refetchMode: 'replace'—SubscriberOptionsnow accepts'replace'as a fourth mode; when resubscribing with cached data, events are buffered and committed as a single replacement rather than streamed live or appended - Synchronous-updater probe for previous data — the subscriber calls
next(undefined, updater)to detect whether SWR cached data exists, without modifying it; if no previous data is found, replace mode falls through to live streaming (same behavior asappend) - Unit and E2E coverage — new tests cover replace with/without previous data,
maxChunksinteraction during buffering, and re-subscription viauseSWRSubscription
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — strengthens the refetchMode: 'replace' e2e test by extracting a mockable streamHandler and using visually distinct replacement data.
- Extracted
streamHandlerexport inpackages/swr/tests/__shared__/orpc.ts— the stream handler is now a namedvi.fnexport, allowing individual e2e tests to mock its implementation without affecting other tests - Distinct replacement data and
vi.waitForin replace-mode e2e test —mockImplementationOnceyields{ output: '__replaced__' }instead of reusing the default'0'/'1'/'2'values, proving the replacement came from the new stream;vi.waitForreplaces asetTimeout-based wait for better reliability
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Summary
Adds
@orpc/swr, the SWR integration for oRPC v2 (successor of v1's@orpc/experimental-react-swr, now marked stable), plus a documentation page.What you get
.key,.fetcher,.mutator,.subscriber,.liveSubscriber,.call, and.matcherforuseSWR,useSWRInfinite,useSWRMutation, anduseSWRSubscription@orpc/tanstack-queryconventions:generateOperationKey,OperationKey, and aprefixoption to avoid key conflicts when multiple router utils share the same clientkeyandtype) is added to the client context on every call, so links can adjust behavior per operation.subscriberand.liveSubscriberconsume an AsyncIteratorObject output, withrefetchModeandmaxChunksoptions for chunked subscriptions@orpc/swradded to the package list across README files