Skip to content

fix(server): pass the submitted input to onError in nextAppDirCaller - #8051

Merged
KATT merged 1 commit into
trpc:mainfrom
LittleChenLiya:fix/next-app-dir-on-error-input
Nov 14, 2026
Merged

KATT merged 1 commit into
trpc:mainfrom
LittleChenLiya:fix/next-app-dir-on-error-input

Conversation

@LittleChenLiya

@LittleChenLiya LittleChenLiya commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Why

What

  • onError gets the input the procedure received, in both the mutation and query branches.
  • A single FormData argument now reaches onError as the normalized object, the same value the procedure got. Before, it got the raw FormData.

Links

  • None

Alternatives considered

  • Keep reading opts.args[0]: still wrong for useActionState.

Testing

  • Regression check: the two new onError tests in packages/server/src/adapters/next-app-dir.test.ts fail without the fix (they get { name: 'stale' } and a raw FormData).

AI model

  • DeepSeek-V4.1-Flash

@LittleChenLiya
LittleChenLiya requested a review from a team as a code owner November 14, 2026 03:38
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
examples-todomvc Ready Ready Preview Nov 14, 2026 3:41am UTC
next-prisma-starter Ready Ready Preview Nov 14, 2026 3:41am UTC
trpc-next-app-dir Ready Ready Preview Nov 14, 2026 3:41am UTC
www Ready Ready Preview Nov 14, 2026 3:41am UTC

Request Review

@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

@LittleChenLiya is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Nov 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@8051

@trpc/next

npm i https://pkg.pr.new/@trpc/next@8051

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@8051

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@8051

@trpc/server

npm i https://pkg.pr.new/@trpc/server@8051

@trpc/tanstack-react-query

npm i https://pkg.pr.new/@trpc/tanstack-react-query@8051

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@8051

commit: 692114a

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

nextAppDirCaller now passes the procedure input to onError for mutation and query failures. New tests check the mutation error callback input when calls use previous state and FormData, or a single FormData argument.

Changes: Next App Router error input

Layer / File(s) Summary
Pass procedure input to error handling
packages/server/src/adapters/next-app-dir/nextAppDirCaller.ts, packages/server/src/adapters/next-app-dir.test.ts
The error handler receives the procedure input, including normalized FormData values. Mutation and query failures pass their respective inputs. Tests check the mutation error callback input for both FormData call shapes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: katt

Merge Risk: Minimal · up to 69211

This change makes onError in the Next App Router adapter receive the input the procedure actually received, instead of the first raw action argument. This fixes error reporting for useActionState and FormData calls. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its scope: onError in nextAppDirCaller now receives the submitted input. The raw summary says the handler previously reported opts.args[0] and now takes the input separatel…
Linked Issues check Passed Issue #8050 requires that nextAppDirCaller report the input the procedure received to onError, not opts.args[0]. At the reviewed head, handleError in packages/server/src/adapters/next-app-dir/nextAppD…
Out of Scope Changes check Passed The diff has three parts. (1) The handleError signature change and the two call-site updates in nextAppDirCaller.ts implement #8050 directly. (2) The onError JSDoc addition documents that input is the…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the fix and its scope: onError in nextAppDirCaller now receives the submitted input. The raw summary says the handler previously reported opts.args[0] and now takes the input separately, and the objectives say mutation and query branches pass the resolved input. The title covers the main change and uses the same terms as the linked issue #8050.

Full details: Linked Issues check

Explanation

Issue #8050 requires that nextAppDirCaller report the input the procedure received to onError, not opts.args[0]. At the reviewed head, handleError in packages/server/src/adapters/next-app-dir/nextAppDirCaller.ts takes the input as a parameter (handleError = (input) => (cause) => ...) and passes it to config.onError. The mutation branch passes its resolved input, which is the second argument under useActionState and is normalized by formDataToObject when normalizeFormData is on. The same value goes to invoke(). The query branch passes opts.args[0], the same value it passes to invoke(). Both branches call .catch(handleError(input)). The PR summary also reports two new onError tests in next-app-dir.test.ts for the stale-state and raw FormData cases. I did not read the test file, so the test behavior rests on the summary. The code change alone satisfies the coding requirement.

Full details: Out of Scope Changes check

Explanation

The diff has three parts. (1) The handleError signature change and the two call-site updates in nextAppDirCaller.ts implement #8050 directly. (2) The onError JSDoc addition documents that input is the normalized value. This supports the fix and changes no public types. (3) The new tests in next-app-dir.test.ts cover the #8050 behavior. No unrelated changes appear in the reviewed diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: trpc/trpc
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 1283c63
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7fbebc97-72da-4524-afa5-af2c7c548f04
Commits

Reviewing files that changed from the base of the PR and between 1283c63 and 692114a.

Files selected for processing: 2

  • packages/server/src/adapters/next-app-dir.test.ts
  • packages/server/src/adapters/next-app-dir/nextAppDirCaller.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@trpc-bot trpc-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checked locally: both new onError tests fail with the source change reverted ({ name: 'stale' } and raw FormData) and pass with it. CI green.


Generated by Claude Code

@KATT
KATT added this pull request to the merge queue Nov 14, 2026
Merged via the queue into trpc:main with commit 1052635 Nov 14, 2026
53 of 57 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 15, 2026

This branch was successfully deployed

4 active deployments
Preview – trpc-next-app-dir — 692114af Deployed Nov 14, 2026 by vercel[bot]
Preview – next-prisma-starter — 692114af Deployed Nov 14, 2026 by vercel[bot]
Preview – examples-todomvc — 692114af Deployed Nov 14, 2026 by vercel[bot]
Preview – www — 692114af Deployed Nov 14, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nextAppDirCaller reports the previous state to onError instead of the submitted input

3 participants