Skip to content

feat(server): extend .actionable error handling for tanstack router compatibility - #1045

Merged
dinwwwh merged 3 commits into
mainfrom
feat/server/support-tanstack-error-in-server-action
Sep 29, 2025
Merged

feat(server): extend .actionable error handling for tanstack router compatibility#1045
dinwwwh merged 3 commits into
mainfrom
feat/server/support-tanstack-error-in-server-action

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Sep 28, 2025

Copy link
Copy Markdown
Member

Allow server actions to properly handle tanstack router navigation errors (redirect, notFound) similar to existing Next.js error support

Summary by CodeRabbit

  • Bug Fixes

    • Improved server-side action error handling so framework-specific redirects and “not found/unauthorized/forbidden” conditions from both Next.js and TanStack Start are correctly rethrown and handled.
  • Tests

    • Updated tests to cover both routing frameworks’ error behaviors and ensure errors are captured and rethrown consistently.
  • Documentation

    • Added a warning noting that special redirect/not-found behaviors are supported only in Next.js and TanStack Start.
  • Chores

    • Added a development-only routing dependency to support test/build workflows.

…ompatibility

Allow server actions to properly handle tanstack router navigation
errors (redirect, notFound) similar to existing Next.js error support
@vercel

vercel Bot commented Sep 28, 2025

Copy link
Copy Markdown

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

Project Deployment Preview Comments Updated (UTC)
orpc Ready Ready Preview Comment Sep 29, 2025 8:47am

@coderabbitai

coderabbitai Bot commented Sep 28, 2025

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds TanStack Router as a devDependency, extends server action error handling to rethrow TanStack Router navigation errors alongside existing Next.js cases, and updates tests and docs to assert and document rethrow behavior for both frameworks.

Changes

Cohort / File(s) Summary
Server action error handling
packages/server/src/procedure-action.ts
Adds isObject import and expands createActionableClient error branches to rethrow Next.js digest errors and TanStack Router-style navigation errors (Response/options or plain objects with isNotFound: true).
Server action tests
packages/server/src/procedure-action.test.ts
Replaces direct next/navigation imports with wildcard, adds @tanstack/router-core import, updates mocks to throw framework errors and asserts rethrow for both Next.js and TanStack Router cases; adjusts test descriptions and control flow to capture/rethrow errors for comparison.
Dev dependency
packages/server/package.json
Adds devDependency: @tanstack/router-core@^1.132.19.
Docs
apps/content/docs/server-action.md
Inserts a warning noting that special navigation errors like redirect and notFound are only supported in Next.js and TanStack Start.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant A as createActionableClient.action
  participant P as Procedure
  Note over C,A: Caller invokes server action
  C->>A: action(input)
  A->>P: execute(input)
  alt Framework navigation error thrown
    note right of P: Next.js Error (digest "NEXT_...")\nTanStack Router Response/options\nPlain object { isNotFound: true }
    P-->>A: throw frameworkError
    A-->>C: rethrow frameworkError
  else Other error thrown
    P-->>A: throw otherError
    A->>C: reject with handled/wrapped error
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • unnoq/orpc#452 — Modifies createActionableClient to rethrow Next.js NEXT_-digest navigation errors; closely related to the added TanStack Router handling in this PR.

Poem

In burrows of bytes where actions hop,
I sniffed two trails—Next and TanStack—nonstop.
If they say “turn back,” I won't interfere,
I pass the message, tidy and clear.
Carrots compiled, tests aligned — a hop well-timed. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly identifies a new feature in the server package and concisely describes the primary change—extending the .actionable client’s error handling to support TanStack Router navigation errors. It uses precise, descriptive language and follows the conventional commit format with a scope and a clear action. A teammate glancing at the history can immediately understand the intent and context of the change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/server/support-tanstack-error-in-server-action

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8579b07 and 338f02b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • apps/content/docs/server-action.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/content/docs/server-action.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 28, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request extends the server-side action error handling to seamlessly integrate with tanstack/router's navigation errors. By introducing specific checks for tanstack/router's redirect and notFound errors, the system ensures these critical navigation events are correctly propagated and handled, mirroring the established behavior for Next.js errors. This enhancement provides a more robust and consistent error management experience across different routing solutions.

Highlights

  • Tanstack Router Compatibility: Server actions now properly handle and rethrow tanstack/router navigation errors, specifically redirect and notFound, aligning with the existing error handling for Next.js.
  • Dependency Update: The @tanstack/router-core package has been added as a development dependency to support the new error handling and testing.
  • Enhanced Test Coverage: New test cases have been introduced to validate the correct rethrowing of tanstack/router errors, and the error assertion logic has been refined for greater precision.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request extends the server action error handling to support navigation errors from TanStack Router, similar to the existing support for Next.js. The changes involve adding a dev dependency, updating tests to cover TanStack Router errors, and adding logic to re-throw these specific errors. My review focuses on the correctness of the new error handling logic. I've found a potential issue in how TanStack Router errors are identified and have suggested a more robust implementation.

Comment thread packages/server/src/procedure-action.ts
@codecov

codecov Bot commented Sep 28, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2025

Copy link
Copy Markdown
More templates

@orpc/arktype

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

@orpc/client

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

@orpc/contract

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

@orpc/experimental-durable-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-iterator@1045

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@1045

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@1045

@orpc/json-schema

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

@orpc/nest

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

@orpc/openapi

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

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@1045

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@1045

@orpc/react

npm i https://pkg.pr.new/@orpc/react@1045

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@1045

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@1045

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@1045

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@1045

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@1045

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@1045

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@1045

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@1045

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@1045

@orpc/tanstack-query

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

@orpc/trpc

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

@orpc/valibot

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

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@1045

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@1045

@orpc/zod

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

commit: 338f02b

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/server/src/procedure-action.test.ts (1)

50-60: Stabilize env var and captured error

Capture for identity compare is solid. Consider resetting the Next experimental env after the test to avoid cross-test leakage.

Apply:

   it.each([
@@
   ])('should rethrow next.js or tanstack router error', async (createError) => {
-    (process as any).env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS = true
+    const prev = (process as any).env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS
+    ;(process as any).env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS = true
@@
-    })
+    }).finally(() => {
+      (process as any).env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS = prev
+    })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e39a46e and 8579b07.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/server/package.json (1 hunks)
  • packages/server/src/procedure-action.test.ts (2 hunks)
  • packages/server/src/procedure-action.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/server/src/procedure-action.ts (1)
packages/shared/src/object.ts (1)
  • isObject (44-52)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
🔇 Additional comments (7)
packages/server/src/procedure-action.ts (3)

5-5: Import looks good

Using isObject avoids prototype-poison issues when probing error shapes.


39-47: Next.js digest rethrow is correct

Covers redirect/forbidden/unauthorized/notFound digests (NEXT_*) in Next 15.


49-55: Dismiss Response-based error detection; use tanstack/router helpers
redirect() throws a plain Redirect object (with statusCode, headers, etc.), not a Web Response, and there’s no built-in options prop. notFound() throws a plain NotFoundError object. Rely on isRedirect(error) and isNotFound(error) from @tanstack/router-core for accurate guards.

Likely an incorrect or invalid review comment.

packages/server/src/procedure-action.test.ts (3)

2-3: Test-only imports are appropriate

Using wildcard imports from next/navigation and @tanstack/router-core keeps runtime free of these deps.


41-47: Good coverage of both Next and TanStack cases

Matrix covers redirect/auth/notFound scenarios for each library.


62-62: Assertion is exact and resilient

rejects.toBe(error) ensures the same instance is rethrown.

packages/server/package.json (1)

139-145: @tanstack/router-core restricted to tests
Search confirms it’s only imported in packages/server/src/procedure-action.test.ts, so devDependency use is correct.

@dinwwwh dinwwwh added the lgtm This PR has been approved by a maintainer label Sep 28, 2025
@dinwwwh
dinwwwh merged commit f677f1d into main Sep 29, 2025
11 checks passed
@dinwwwh
dinwwwh deleted the feat/server/support-tanstack-error-in-server-action branch June 22, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant