feat(server): extend .actionable error handling for tanstack router compatibility - #1045
Conversation
…ompatibility Allow server actions to properly handle tanstack router navigation errors (redirect, notFound) similar to existing Next.js error support
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ 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)
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. Comment |
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/server/src/procedure-action.test.ts (1)
50-60: Stabilize env var and captured errorCapture 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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 goodUsing
isObjectavoids prototype-poison issues when probing error shapes.
39-47: Next.js digest rethrow is correctCovers
redirect/forbidden/unauthorized/notFounddigests (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 appropriateUsing wildcard imports from
next/navigationand@tanstack/router-corekeeps runtime free of these deps.
41-47: Good coverage of both Next and TanStack casesMatrix 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 inpackages/server/src/procedure-action.test.ts, so devDependency use is correct.
Allow server actions to properly handle tanstack router navigation errors (redirect, notFound) similar to existing Next.js error support
Summary by CodeRabbit
Bug Fixes
Tests
Documentation
Chores