Skip to content

feat(swr): SWR integration#1723

Merged
dinwwwh merged 8 commits into
middleapi:mainfrom
dinwwwh:claude/orpc-v2-react-swr-ef0f1e
Jul 25, 2026
Merged

feat(swr): SWR integration#1723
dinwwwh merged 8 commits into
middleapi:mainfrom
dinwwwh:claude/orpc-v2-react-swr-ef0f1e

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Jul 25, 2026

Copy link
Copy Markdown
Member

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.

import { createSWRUtils } from '@orpc/swr'

const orpc = createSWRUtils(client)

const { data } = useSWR(
  orpc.planet.find.key({ input: { id: 123 } }),
  orpc.planet.find.fetcher(),
)

const mutation = useSWRMutation(
  orpc.planet.list.key(),
  orpc.planet.create.mutator(),
)

mutate(orpc.planet.matcher()) // invalidate all planet data

What you get

  • .key, .fetcher, .mutator, .subscriber, .liveSubscriber, .call, and .matcher for useSWR, useSWRInfinite, useSWRMutation, and useSWRSubscription
  • Key utils follow the @orpc/tanstack-query conventions: generateOperationKey, OperationKey, and a prefix option to avoid key conflicts when multiple router utils share the same client
  • Operation context (with key and type) is added to the client context on every call, so links can adjust behavior per operation
  • .subscriber and .liveSubscriber consume an AsyncIteratorObject output, with refetchMode and maxChunks options for chunked subscriptions
  • 100% test coverage
  • @orpc/swr added to the package list across README files

@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview, Comment Jul 25, 2026 9:04am

@pkg-pr-new

pkg-pr-new Bot commented Jul 25, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1723

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1723

@orpc/bun

npm i https://pkg.pr.new/@orpc/bun@1723

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1723

@orpc/cloudflare

npm i https://pkg.pr.new/@orpc/cloudflare@1723

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1723

@orpc/experimental-effect

npm i https://pkg.pr.new/@orpc/experimental-effect@1723

@orpc/evlog

npm i https://pkg.pr.new/@orpc/evlog@1723

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1723

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1723

@orpc/next

npm i https://pkg.pr.new/@orpc/next@1723

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1723

@orpc/opentelemetry

npm i https://pkg.pr.new/@orpc/opentelemetry@1723

@orpc/pinia-colada

npm i https://pkg.pr.new/@orpc/pinia-colada@1723

@orpc/pino

npm i https://pkg.pr.new/@orpc/pino@1723

@orpc/publisher

npm i https://pkg.pr.new/@orpc/publisher@1723

@orpc/ratelimit

npm i https://pkg.pr.new/@orpc/ratelimit@1723

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1723

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1723

@orpc/swr

npm i https://pkg.pr.new/@orpc/swr@1723

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1723

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1723

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1723

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1723

commit: bea4be2

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing dinwwwh:claude/orpc-v2-react-swr-ef0f1e (bea4be2) with main (cfe1839)

Open in CodSpeed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ One minor consistency note.

Reviewed changes — adds @orpc/react-swr, the SWR integration for oRPC v2, following the same SharedUtilsProcedureUtilscreateRouterUtils architecture as @orpc/tanstack-query and @orpc/pinia-colada.

  • New @orpc/react-swr package — provides .key, .fetcher, .mutator, .subscriber, .liveSubscriber, .call, and .matcher for useSWR, useSWRInfinite, useSWRMutation, and useSWRSubscription
  • Key generation and matchergenerateOperationKey with optional prefix for avoiding key conflicts; SharedUtils.matcher with partial/exact strategies powered by isSubsetOf
  • Operation contextOPERATION_CONTEXT_SYMBOL is injected into client context on every call, allowing links to adjust HTTP methods or other behavior per operation type
  • Subscription support.subscriber and .liveSubscriber consume AsyncIteratorObject output with refetchMode and maxChunks options
  • Documentation — new apps/content/docs/integrations/react-swr.md page 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.json devDependencies is missing @orpc/react-swr@orpc/tanstack-query is listed there; adding it keeps the monorepo scaffolding consistent.

Pullfrog  | Fix it ➔View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@dinwwwh dinwwwh changed the title feat(react-swr): React SWR integration feat(swr): SWR integration Jul 25, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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/swr with directory packages/react-swr/packages/swr/; all source files, tests, READMEs (24+), docs page, VitePress config, vitest.config.ts, and pnpm-lock.yaml consistently updated
  • SWR version bump — peer dependency raised from >=2.3.6 to >=2.4.2, dev dependency from ^2.4.1 to ^2.4.2
  • Docs pageapps/content/docs/integrations/react-swr.md renamed to swr.md with all import paths, install commands, and JSDoc @see URLs updated to the new package name

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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'SubscriberOptions now 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 as append)
  • Unit and E2E coverage — new tests cover replace with/without previous data, maxChunks interaction during buffering, and re-subscription via useSWRSubscription

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — strengthens the refetchMode: 'replace' e2e test by extracting a mockable streamHandler and using visually distinct replacement data.

  • Extracted streamHandler export in packages/swr/tests/__shared__/orpc.ts — the stream handler is now a named vi.fn export, allowing individual e2e tests to mock its implementation without affecting other tests
  • Distinct replacement data and vi.waitFor in replace-mode e2e testmockImplementationOnce yields { output: '__replaced__' } instead of reusing the default '0'/'1'/'2' values, proving the replacement came from the new stream; vi.waitFor replaces a setTimeout-based wait for better reliability

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh merged commit d438821 into middleapi:main Jul 25, 2026
11 checks passed
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