fix(client): respect user-provided mapSubresponse in BatchLinkPlugin - #1848
Conversation
The constructor assigned the default implementation unconditionally instead of using the `options.mapSubresponse ?? ...` fallback every other option uses, so a custom mapSubresponse was silently ignored.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
batch.ts:164—BatchLinkPluginconstructor now honors a user-providedmapSubresponseviaoptions.mapSubresponse ?? <default>, fixing the silent ignore bug. Matches the?? defaultpattern used by every other option.batch.test.ts:411— new test supplying a custommapSubresponse(tags headers, rewrites body), asserting it runs once per sub-request and its headers/body reach the codec and caller, and that the default batch-header merge is replaced rather than layered on.
The fix is minimal and correct, and the test genuinely fails on the unpatched code — without the fix mapSubresponse would never be called, the resolved body would be result-0 instead of mapped-result-0, and the batch response header would still be merged. Default behavior (option omitted) is unchanged, and no JSDoc update is needed since @default still describes the default. Verified: pnpm vitest run packages/client/src/plugins/batch.test.ts → 28 passed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/hibernation
@orpc/json-schema
@orpc/nest
@orpc/next
@orpc/node
@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! |

A custom
mapSubresponsepassed toBatchLinkPluginwas silently ignored: the constructor assigned the built-in implementation unconditionally instead of using theoptions.mapSubresponse ?? ...fallback that every other option uses. Users who supplied the hook to rewrite sub-responses got the default header merge instead, with no error or warning.Fixes
A user-provided
mapSubresponsenow runs for every sub-request, and the response it returns (headers and body alike) is what reaches the caller. Behavior is unchanged when the option is omitted.Testing
New test in
packages/client/src/plugins/batch.test.tssupplies a custommapSubresponsethat tags headers and rewrites the body, then asserts it is called once per sub-request, that its headers reach the codec, and that its body is whatlink.callresolves to. The batch response carries its own header so the test also confirms the default merge is replaced rather than layered on. The test fails on the unpatched plugin and passes with the fix.