Skip to content

feat(server, react)!: remake server action#308

Merged
dinwwwh merged 24 commits into
mainfrom
feat/server-react/remake-server-action
Mar 30, 2025
Merged

feat(server, react)!: remake server action#308
dinwwwh merged 24 commits into
mainfrom
feat/server-react/remake-server-action

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Mar 29, 2025

Entirely rewrite server action for oRPC and comewith some utilities and hooks for react

Summary by CodeRabbit

  • New Features

    • Introduced a dedicated React integration package that delivers utilities for executing server actions and handling form submissions.
    • Enabled experimental support in Next.js for enhanced authentication handling.
  • Documentation

    • Updated guides and package overviews to highlight the new React integration capabilities.
  • Chores

    • Refreshed dependencies and configurations for Next.js and React.
  • Tests

    • Expanded test coverage to validate the new integration utilities and enhanced workflows.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 30, 2025 1:43am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 29, 2025

Walkthrough

This PR introduces the new @orpc/react package, adding utilities for React integration and React Server Actions. Documentation across various README files has been updated to include its entry. In addition, several type signature refinements, new tests, and configuration updates have been implemented across client, server, and playground code. New files and exports have been added for hooks, form actions, and actionable procedures, and dependency versions have been updated accordingly.

Changes

File(s) Change Summary
README.md, apps/content/docs/*, packages/{arktype,client,contract,openapi*,react-query,server,shared,solid-query,standard-server*,svelte-query,valibot,vue-colada,vue-query,zod}/README.md Updated documentation to add new @orpc/react package entry and revise React Server Actions details
apps/content/package.json, playgrounds/nextjs/package.json, packages/react-query/package.json Added dependency on @orpc/react and updated versions for Next.js, React, and related packages
packages/react/{.gitignore,README.md,package.json,src/index.ts,tsconfig.json,src/hooks/*,src/action-form*,...} Created new @orpc/react package with exports, configuration files, utilities (useServerAction, createFormAction), and corresponding tests
packages/client/src/types.test-d.ts Updated type tests by replacing fn with a new client function having a revised type signature
packages/server/src/{implementer-procedure*, index.ts, procedure-action*, procedure-decorated*} Refined actionable procedure types and client interfaces; introduced createActionableClient and improved error handling
packages/shared/src/interceptor* Updated interceptor types to include detailed error handling with an extended return type
playgrounds/nextjs/{next.config.ts,src/app/actions.ts,src/app/orpc-server-action.tsx,src/app/page.tsx} Introduced a new server action flow with a dosomething action, form submission via redirectToScalarForm, and an experimental auth interruption feature
packages/react/src/{action-form.test.ts,action-form.ts,hooks/action-hooks*,hooks/index.ts} Added tests and implementation for form actions and the useServerAction hook with comprehensive state management

Sequence Diagram(s)

sequenceDiagram
  participant C as React Component
  participant H as useServerAction Hook
  participant A as ActionableClient
  participant S as Server

  C->>H: Invoke execute(input)
  H->>A: Call actionable client with input
  A->>S: Request processing (RPC)
  S-->>A: Return data / error
  A-->>H: Pass response
  H-->>C: Update state (idle → pending → success/error)
Loading
sequenceDiagram
  participant U as User
  participant F as Form (redirectToScalarForm)
  participant CA as createFormAction
  participant D as dosomething Procedure
  participant I as onSuccess Interceptor
  participant R as Response (redirect)

  U->>F: Submit form data
  F->>CA: Process form action
  CA->>D: Invoke dosomething action with input
  D-->>CA: Return result or error
  CA->>I: Trigger onSuccess interceptor
  I-->>CA: Return redirect signal
  CA-->>F: Complete action (redirect)
  F-->>U: Redirect to Scalar Client Page
Loading

Possibly related PRs

  • unnoq/orpc#181: Updates to README documentation and new entries for framework integrations complement these changes by enhancing the overall documentation consistency across packages.

Poem

I'm a rabbit, hopping with glee,
New code paths bloom like a spring spree.
React hooks and actions now dance in the night,
With @orpc/react, our future shines bright.
Lines of code and tests all sing in tune,
A joyful leap toward a smarter moon!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 29, 2025

Open in Stackblitz

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/openapi

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

@orpc/contract

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

@orpc/openapi-client

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

@orpc/react

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/svelte-query

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 927dd64

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (24)
packages/client/README.md (1)

56-56: Add @orpc/react Entry for React Integration
The new bullet clearly informs users about the @orpc/react package and its role in providing utilities for integrating oRPC with React and React Server Actions. The entry is consistent with similar ones in other packages’ READMEs.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/standard-server-fetch/README.md (1)

56-56: Introduce @orpc/react in Standard Server Fetch Documentation
This addition succinctly explains the new React integration utility. It aligns well with how the package list is structured in the project. You might consider a slight rewording of sentence beginnings if the static analysis hint about repetitive phrasing becomes an issue.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/shared/README.md (1)

61-61: Document @orpc/react Addition in Shared Package README
The update adds a clear and useful entry for the new package. Its description effectively communicates that the package provides utilities for React integration. The uniform style is good; however, you may recheck the phrasing if the static analysis regarding repeated sentence starts persists.

🧰 Tools
🪛 LanguageTool

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/openapi/README.md (1)

56-56: Update with @orpc/react Entry in OpenAPI Documentation
The entry for @orpc/react is well-integrated in the packages list. It clearly states that the package delivers utilities for integrating with React and React Server Actions, which aligns perfectly with the overall documentation update. Consider addressing the static analysis note about repetitive sentence structures if needed.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/arktype/README.md (1)

56-56: Add @orpc/react Documentation in ArkType README
This change maintains consistency by adding the new package entry for @orpc/react, along with its clear description as a utility for React integration. The structure matches other README files in the repo. A minor stylistic tweak might be considered if the repeated sentence beginnings flagged by static analysis become a concern.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/standard-server-node/README.md (1)

51-57: Suggestion: Vary Bullet List Descriptions.
A static analysis hint noted that successive bullet points may start with similar phrasing. Consider varying the opening words of each description to enhance readability.

🧰 Tools
🪛 LanguageTool

[style] ~55-~55: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... your API or implement API contract. - [@orpc/client](https://www.npmjs.com/package/@...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~57-~57: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...with React and React Server Actions. - [@orpc/react-query](https://www.npmjs.com/pack...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/contract/README.md (1)

51-57: Minor Suggestion on Bullet Descriptions.
To improve clarity and flow, you might consider varying the introductory language across successive bullet points.

🧰 Tools
🪛 LanguageTool

[style] ~55-~55: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... your API or implement API contract. - [@orpc/client](https://www.npmjs.com/package/@...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~57-~57: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...with React and React Server Actions. - [@orpc/react-query](https://www.npmjs.com/pack...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/svelte-query/README.md (1)

51-57: Suggestion: Vary Bullet Sentence Openings.
Consider using varied phrasing in the bullet list to avoid repetitive sentence openings, which can help improve overall readability.

🧰 Tools
🪛 LanguageTool

[style] ~55-~55: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... your API or implement API contract. - [@orpc/client](https://www.npmjs.com/package/@...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~57-~57: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...with React and React Server Actions. - [@orpc/react-query](https://www.npmjs.com/pack...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/server/README.md (1)

51-57: Nitpick: Bullet List Sentence Variation.
To further enhance the documentation’s readability, consider rephrasing some of the bullet point descriptions so they don’t all start with the same word or structure.

🧰 Tools
🪛 LanguageTool

[style] ~55-~55: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... your API or implement API contract. - [@orpc/client](https://www.npmjs.com/package/@...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~57-~57: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...with React and React Server Actions. - [@orpc/react-query](https://www.npmjs.com/pack...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/vue-colada/README.md (1)

56-56: New @orpc/react Package Entry Added
The new package entry clearly describes @orpc/react as providing "Utilities for integrating oRPC with React and React Server Actions." This addition is consistent with similar entries in other documentation files.

Consider reviewing the phrasing if LanguageTool hints about repeated sentence beginnings become an issue—even though the style here is already in line with the other entries.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/solid-query/README.md (1)

56-56: New @orpc/react Package Entry Added
The entry for @orpc/react is added with a succinct and clear description that matches the pattern used in the rest of the document. This consistency improves discoverability for developers seeking React integration details.

A minor stylistic review is recommended if any repetitive sentence structure warnings appear, but the current format is acceptable.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/valibot/README.md (1)

56-56: New @orpc/react Package Entry Added
This new entry describes @orpc/react effectively as "Utilities for integrating oRPC with React and React Server Actions." The entry aligns well with the other package descriptions across the project.

You might consider a brief stylistic review to avoid potential LanguageTool flags regarding similar sentence beginnings, though this is a minor nitpick.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/standard-server/README.md (1)

56-56: New @orpc/react Package Entry Added
The inclusion of @orpc/react in the Packages section, with its clear description, is a great addition. It helps users quickly identify relevant integration utilities for React and React Server Actions.

Ensure that the formatting and language style remains consistent with other entries. A small adjustment to diversify sentence openings might be beneficial if similar warnings arise.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/zod/README.md (1)

56-56: New @orpc/react Package Entry Added
The update adds the @orpc/react package with a straightforward explanation, matching the style of similar entries in other READMEs. This helps reinforce the availability of React-specific utilities across the project.

A slight rewording could be considered in the future if repetitive sentence patterns trigger stylistic alerts, but the current implementation is clear and consistent.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

playgrounds/nextjs/src/app/orpc-server-action.tsx (1)

8-14: Consider adding error handling to the server action

The implementation uses the new hook and success interceptor pattern, which is good. However, there's no error handling in place.

Consider adding an error interceptor to provide feedback when actions fail:

 const state = useServerAction(getting, {
   interceptors: [
     onSuccess((message) => {
       alert(message)
     }),
+    onError((error) => {
+      alert(`Error: ${error.message}`)
+    }),
   ],
 })
playgrounds/nextjs/src/app/actions.ts (1)

19-30: Add return type and error handling to the procedure

The dosomething procedure logs input but doesn't have explicit error handling or a defined return type.

Consider enhancing the procedure with type definitions and error handling:

 const dosomething = pub
   .input(z.object({
     user: z.object({
       name: z.string(),
       age: z.coerce.number(),
     }),
   }))
+  .output(z.void())
   .handler(({ input }) => {
     console.log('An form action was called!')
     console.log(input)
+    // Consider error handling here
+    // if (someCondition) throw new Error('Invalid input')
   })
packages/react/src/action-hooks.test.tsx (1)

7-16: Consider handling undefined input more explicitly.
Although the input schema is optional, you might want to ensure that an undefined input is handled gracefully or defaults to a specific value to prevent potential edge cases.

packages/react/src/server/action-form.ts (1)

13-22: Interceptor design is valid; consider additional statuses if needed.
Transforming 401, 403, 404 to Next.js-friendly errors covers key scenarios. If you also handle other codes (e.g., 500), consider extending this approach. Otherwise, this is a sound interceptor.

packages/react/README.md (1)

146-156: Sponsors and license information properly included.

The README appropriately acknowledges sponsors and licensing information.

However, there's a minor issue in the sponsors image:

-  <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
-    <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
+  <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
+    <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg' alt="Sponsors"/>

Adding the alt attribute to the image would improve accessibility and fix the static analysis warning.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

150-150: Images should have alternate text (alt text)
null

(MD045, no-alt-text)

packages/server/src/procedure-decorated.ts (3)

130-133: Avoid Casting to any for Stronger Type Safety

In the callable method, ...rest as any can undermine type safety. Consider preserving or refining parameter types to maintain strict typing instead of resorting to as any.


159-162: Further Type-Safety Possible

While constructing the action client, consider avoiding ...rest as any to maintain strict typing, similar to the caution given in the callable method.


163-170: Consider Extracting Shared Proxy Logic

Returning a Proxy here mirrors the pattern in callable. If multiple methods use the same reflection approach, factoring this into a shared helper could reduce duplication.

packages/react/src/action-hooks.ts (2)

103-141: Consider concurrency handling and canceled updates on unmounted components.
If multiple calls to execute() happen in quick succession or if the component is unmounted before a call completes, the final state could be inaccurate or cause an attempted state update after unmount. Consider implementing concurrency control or an abort mechanism.


147-153: Avoid casting the final result to any.
Casting the hook’s return value to any reduces type-safety, potentially obscuring type errors. Instead, use proper type assertions or rely on TypeScript inference to ensure safe return types.

-  return result as any
+  return result
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54ba24c and be9dffd.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (50)
  • README.md (1 hunks)
  • apps/content/docs/procedure.md (1 hunks)
  • apps/content/docs/server-action.md (2 hunks)
  • apps/content/package.json (1 hunks)
  • packages/arktype/README.md (1 hunks)
  • packages/client/README.md (1 hunks)
  • packages/client/src/types.test-d.ts (2 hunks)
  • packages/contract/README.md (1 hunks)
  • packages/openapi-client/README.md (1 hunks)
  • packages/openapi/README.md (1 hunks)
  • packages/react-query/README.md (1 hunks)
  • packages/react/.gitignore (1 hunks)
  • packages/react/README.md (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/src/action-hooks.test-d.ts (1 hunks)
  • packages/react/src/action-hooks.test.tsx (1 hunks)
  • packages/react/src/action-hooks.ts (1 hunks)
  • packages/react/src/index.ts (1 hunks)
  • packages/react/src/server/action-form.test.ts (1 hunks)
  • packages/react/src/server/action-form.ts (1 hunks)
  • packages/react/src/server/index.ts (1 hunks)
  • packages/react/tsconfig.json (1 hunks)
  • packages/server/README.md (1 hunks)
  • packages/server/src/implementer-procedure.test-d.ts (3 hunks)
  • packages/server/src/implementer-procedure.ts (2 hunks)
  • packages/server/src/index.ts (1 hunks)
  • packages/server/src/procedure-action.test-d.ts (1 hunks)
  • packages/server/src/procedure-action.test.ts (1 hunks)
  • packages/server/src/procedure-action.ts (1 hunks)
  • packages/server/src/procedure-decorated.test-d.ts (2 hunks)
  • packages/server/src/procedure-decorated.test.ts (3 hunks)
  • packages/server/src/procedure-decorated.ts (3 hunks)
  • packages/shared/README.md (1 hunks)
  • packages/shared/src/interceptor.test-d.ts (4 hunks)
  • packages/shared/src/interceptor.ts (1 hunks)
  • packages/solid-query/README.md (1 hunks)
  • packages/standard-server-fetch/README.md (1 hunks)
  • packages/standard-server-node/README.md (1 hunks)
  • packages/standard-server/README.md (1 hunks)
  • packages/svelte-query/README.md (1 hunks)
  • packages/valibot/README.md (1 hunks)
  • packages/vue-colada/README.md (1 hunks)
  • packages/vue-query/README.md (1 hunks)
  • packages/zod/README.md (1 hunks)
  • playgrounds/nextjs/next.config.ts (1 hunks)
  • playgrounds/nextjs/package.json (2 hunks)
  • playgrounds/nextjs/src/app/actions.ts (2 hunks)
  • playgrounds/nextjs/src/app/orpc-server-action.tsx (1 hunks)
  • playgrounds/nextjs/src/app/page.tsx (2 hunks)
  • vitest.workspace.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (9)
playgrounds/nextjs/src/app/actions.ts (4)
playgrounds/nextjs/src/orpc.ts (1)
  • pub (5-6)
packages/react/src/server/action-form.ts (1)
  • createFormAction (24-56)
playgrounds/nextjs/src/app/orpc-mutation.tsx (1)
  • onSuccess (11-15)
packages/server/src/index.ts (1)
  • onSuccess (39-39)
packages/server/src/procedure-action.test.ts (1)
packages/server/src/procedure-action.ts (1)
  • createActionableClient (29-42)
packages/react/src/action-hooks.test-d.ts (1)
packages/react/src/action-hooks.ts (1)
  • useServerAction (84-154)
packages/server/src/implementer-procedure.ts (2)
packages/server/src/procedure-client.ts (1)
  • CreateProcedureClientOptions (44-68)
packages/server/src/procedure-action.ts (1)
  • ProcedureActionableClient (19-27)
packages/server/src/procedure-decorated.test-d.ts (3)
packages/server/src/procedure-action.ts (2)
  • ActionableClient (15-17)
  • ActionableError (5-5)
packages/contract/src/error.ts (1)
  • ErrorFromErrorMap (43-43)
packages/contract/tests/shared.ts (1)
  • baseErrorMap (12-17)
packages/server/src/procedure-decorated.ts (2)
packages/server/src/procedure-client.ts (3)
  • ProcedureClient (14-24)
  • createProcedureClient (70-123)
  • CreateProcedureClientOptions (44-68)
packages/server/src/procedure-action.ts (2)
  • ProcedureActionableClient (19-27)
  • createActionableClient (29-42)
packages/server/src/implementer-procedure.test-d.ts (3)
packages/server/src/procedure-action.ts (2)
  • ActionableClient (15-17)
  • ActionableError (5-5)
packages/contract/src/error.ts (1)
  • ErrorFromErrorMap (43-43)
packages/contract/tests/shared.ts (1)
  • baseErrorMap (12-17)
packages/react/src/server/action-form.test.ts (1)
packages/react/src/server/action-form.ts (1)
  • createFormAction (24-56)
packages/server/src/procedure-action.ts (1)
packages/server/src/index.ts (4)
  • ORPCError (23-23)
  • ErrorMap (29-29)
  • InferSchemaInput (31-31)
  • InferSchemaOutput (32-32)
🪛 LanguageTool
packages/react-query/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/client/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/shared/README.md

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/vue-query/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/openapi/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/standard-server-node/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/server/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/contract/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/standard-server/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/openapi-client/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/arktype/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/zod/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/standard-server-fetch/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/solid-query/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/react/README.md

[misspelling] ~35-~35: Possible spelling mistakes found.
Context: ...tack Query (React, Vue, Solid, Svelte), Pinia Colada, and more. - Server Actions ⚡️: Ful...

(EN_MULTITOKEN_SPELLING_TWO)


[style] ~55-~55: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... your API or implement API contract. - [@orpc/client](https://www.npmjs.com/package/@...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~57-~57: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...with React and React Server Actions. - [@orpc/react-query](https://www.npmjs.com/pack...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~58-~58: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...test/docs/framework/react/overview). - [@orpc/vue-query](https://www.npmjs.com/packag...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~59-~59: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...latest/docs/framework/vue/overview). - [@orpc/solid-query](https://www.npmjs.com/pack...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~60-~60: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...test/docs/framework/solid/overview). - [@orpc/svelte-query](https://www.npmjs.com/pac...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...est/docs/framework/svelte/overview). - [@orpc/vue-colada](https://www.npmjs.com/packa...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[misspelling] ~61-~61: Possible spelling mistakes found.
Context: ...ge/@orpc/vue-colada): Integration with Pinia Colada. - [@or...

(EN_MULTITOKEN_SPELLING_TWO)


[style] ~62-~62: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ada](https://pinia-colada.esm.dev/). - [@orpc/openapi](https://www.npmjs.com/package/...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~63-~63: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...I specs and handle OpenAPI requests. - [@orpc/zod](https://www.npmjs.com/package/@orp...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~64-~64: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...tps://zod.dev/) doesn't support yet. - [@orpc/valibot](https://www.npmjs.com/package/...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~65-~65: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...rom Valibot. - [@orpc/arktype](https://www.npmjs.com/package/...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/valibot/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/vue-colada/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/svelte-query/README.md

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🪛 markdownlint-cli2 (0.17.2)
packages/react/README.md

150-150: Images should have alternate text (alt text)
null

(MD045, no-alt-text)

🪛 GitHub Actions: CI
packages/react/src/action-hooks.test.tsx

[error] 32-32: You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);


[error] 67-67: TypeError: Cannot read properties of null (reading 'status')


[error] 124-124: TypeError: Cannot read properties of null (reading 'execute')

🔇 Additional comments (98)
packages/react/src/server/index.ts (1)

1-2: LGTM: New export provides access to action-form functionality

The export statement correctly exposes the action-form module, which appears to be part of the new React server action functionality mentioned in the PR objectives.

packages/react/src/index.ts (1)

1-2: LGTM: New export for action-hooks provides client-side access

This export statement correctly exposes the action-hooks module at the package level, allowing consumers to import hooks for interacting with server actions directly from @orpc/react.

apps/content/package.json (1)

16-16: LGTM: Added @orpc/react dependency to content app

The addition of the @orpc/react workspace dependency is consistent with the PR's objective of adding React utilities and hooks for server actions. Using a workspace reference ensures the content app always uses the local version during development.

packages/server/src/index.ts (1)

14-14:

Details

✅ Verification successful

LGTM: New export provides access to procedure-action functionality

This export statement correctly exposes the procedure-action module, which is likely a key component of the server action rewrite mentioned in the PR objectives. This allows consumers to access the server-side functionality for creating actionable procedures.

I recommend verifying that all necessary types from this module are properly exported to ensure API consistency.


🏁 Script executed:

#!/bin/bash
# Check what's being exported from procedure-action module and verify its completeness
cat packages/server/src/procedure-action.ts | grep -E "export |export type" | grep -v "from"

Length of output: 800


LGTM: Confirmed complete re-export of procedure-action features

The re-export in packages/server/src/index.ts properly exposes the procedure-action module. Our check confirms that key types and functions—such as ActionableError, UnactionableError, ActionableClientRest, ActionableClientResult, ActionableClient, ProcedureActionableClient, and createActionableClient—are being exported. Please verify that the definition for ActionableClientRest is complete and aligned with the intended API design.

apps/content/docs/procedure.md (1)

31-31: Clarify .actionable() Usage.
The updated comment "Server Action compatibility" succinctly captures the purpose of the .actionable() modifier, improving clarity on how this procedure integrates with server actions.

packages/standard-server-node/README.md (1)

56-56: New Package Entry for @orpc/react.
The addition of the @orpc/react package in the Packages section clearly informs users about its role in integrating oRPC with React and React Server Actions.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/contract/README.md (1)

56-56: Consistent Addition of @orpc/react Entry.
The new bullet entry for @orpc/react enhances the package documentation by clearly stating its purpose, ensuring consistency with similar additions across the repository.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/svelte-query/README.md (1)

56-56: New Documentation Entry for @orpc/react.
The bullet entry for @orpc/react clearly communicates its functionality—providing utilities for integrating oRPC with React and React Server Actions—while remaining consistent with the updates in other package READMEs.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/server/README.md (1)

56-56: Addition of @orpc/react Package.
Including the @orpc/react package in the Packages list is well documented and helps users quickly locate the tools for integrating React with oRPC server actions.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

playgrounds/nextjs/next.config.ts (1)

11-13:

Details

✅ Verification successful

Enabled Next.js experimental authentication feature

The addition of the authInterrupts experimental feature in Next.js configuration aligns with the server action rewrite objectives of this PR. This feature enhances authentication handling during server actions.


🏁 Script executed:

#!/bin/bash
# Verify if this Next.js experimental feature is documented or referenced elsewhere
rg "authInterrupts" --type md

Length of output: 29


I'm not seeing any Markdown documentation references for authInterrupts with the previous search. To further confirm its usage and documentation across the entire repository (and not just in Markdown files), please run the following shell script:

This extended search will help us verify if the experimental feature is referenced anywhere else in the codebase, ensuring we don't miss any related documentation or usage.


🏁 Script executed:

#!/bin/bash
# Search for "authInterrupts" references across the entire repository
rg "authInterrupts"

Length of output: 79


Action: Approved – Experimental Feature Integration Verified

The integration of the authInterrupts experimental feature in the Next.js configuration (located in playgrounds/nextjs/next.config.ts at lines 11–13) aligns with the server action rewrite objectives in this PR. Our repository-wide search confirms that this flag is only referenced in this configuration file, and no additional documentation or conflicting usage was found elsewhere.

  • Location: playgrounds/nextjs/next.config.ts (lines 11–13)
  • Snippet:
      experimental: {
        authInterrupts: true,
      },

Given its experimental nature, please ensure that you perform thorough manual testing of related authentication flows as the feature evolves in future Next.js releases.

README.md (1)

56-56: Documentation updated with new @orpc/react package

The addition of the @orpc/react package to the documentation is appropriate and aligns with the PR objectives of introducing React utilities and hooks.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/react-query/README.md (1)

56-56: Documentation updated with new @orpc/react package

Adding the @orpc/react package reference to this package's README maintains documentation consistency across the project and informs users about the new React integration capabilities.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/vue-query/README.md (1)

56-56: Documentation updated with new @orpc/react package

Including the @orpc/react package reference in the Vue Query README demonstrates good cross-package documentation practice, ensuring users are aware of all available integration options regardless of which package documentation they're viewing.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

packages/shared/src/interceptor.test-d.ts (2)

8-8: Updated return type expectation to include error handling

The type test has been updated to reflect the enhanced return type of options.next(), which now includes an optional __error property. This matches the changes in the interceptor implementation to support rich error handling.


18-18: Consistent error type handling across all interceptors

The same return type expectation has been consistently applied to all interceptor functions (onStart, onSuccess, onError, onFinish), ensuring uniform error handling throughout the interceptor chain.

Also applies to: 28-28, 38-38

packages/openapi-client/README.md (1)

56-56: Documentation added for new @orpc/react package

The README has been updated to include information about the new @orpc/react package, which provides utilities for integrating oRPC with React and React Server Actions. This aligns with the PR objective of introducing utilities and hooks for React.

🧰 Tools
🪛 LanguageTool

[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

vitest.workspace.ts (1)

19-19: Updated test configuration for new React package

The test configuration has been modified to include tests from the new react package instead of the next package. This change ensures that tests for the newly introduced React utilities are included in the test suite.

playgrounds/nextjs/src/app/page.tsx (2)

1-1: Added import for new server action function

The redirectToScalarForm function is imported from the actions module to support the new form-based redirection approach.


10-18: Replaced link with form using server action

This change demonstrates practical usage of the new React Server Actions functionality. The previous link to the Scalar API reference has been replaced with a form that submits to the redirectToScalarForm action, passing user information as hidden inputs.

The form implementation showcases how the new @orpc/react utilities can be used with React Server Actions for form submissions and redirects in a Next.js application.

packages/react/tsconfig.json (1)

1-16: TypeScript configuration for React package looks good!

The configuration extends the base library config and correctly excludes test files, benchmarks, and other non-source files from compilation. The empty types array is fine if the base configuration already includes necessary types.

packages/react/.gitignore (1)

1-26: Well-structured .gitignore file

This .gitignore follows best practices by ignoring common generated directories, build artifacts, logs, and sensitive files while appropriately allowing tracked exceptions.

playgrounds/nextjs/src/app/orpc-server-action.tsx (2)

3-5: Proper import of new React hook and client utilities

The imports correctly bring in the new useServerAction hook and the onSuccess interceptor for handling successful action responses.


16-19: Form action no longer awaits the result

The form action now uses the state's execute method instead of directly awaiting the result. This is the correct approach with the useServerAction hook as response handling is delegated to interceptors.

playgrounds/nextjs/src/app/actions.ts (2)

5-7: Appropriate imports for form actions and navigation

The imports correctly bring in the necessary utilities for creating form actions and handling navigation.


31-37: Form action with redirect follows Next.js best practices

The implementation of redirectToScalarForm correctly uses createFormAction with the onSuccess interceptor to handle navigation after form submission. This follows Next.js best practices for handling redirects after server actions.

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

4-4: Import looks good for the new actionable client functionality.

The import statement correctly adds the new createActionableClient function that will be tested within this file.


19-22: Mock implementation looks well-structured.

The new mock for procedure-action follows the same pattern as the existing mocks in the file, which is good for consistency. It preserves the original module exports while adding a mock implementation for createActionableClient.


141-143: Test assertions correctly verify actionable client creation.

These assertions ensure that createActionableClient is called exactly once and with the correct parameter (the result from the mocked createProcedureClient). This properly tests the integration between the procedure client and the actionable client.

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

1-13: Tests for successful action execution look good.

The test correctly verifies that createActionableClient returns the expected format [null, result] on success and that the original client is called with the correct input.


15-20: ORPCError handling test is well-implemented.

This test correctly validates that when the client throws an ORPCError, the action returns it in the expected format with the error details in the first element of the array and undefined in the second.


22-27: Non-ORPCError handling test provides good coverage.

The test verifies that when a generic Error is thrown, it's properly converted to a standard internal server error format, which is important for consistent error handling.


29-36: Security test for ignoring additional arguments is valuable.

This test is important as it verifies that extra arguments passed to the action are ignored, preventing potential security issues or unexpected behavior when users misuse the API.

packages/react/package.json (4)

1-17: Package metadata is well-structured.

The package metadata follows best practices with appropriate name, version, license, and repository information. The keywords are relevant to the package's purpose.


18-35: Export configuration is clean and supports multiple entry points.

The export configuration properly defines both CommonJS and ESM entry points for the main package and a server-specific entry point, which is important for React Server Components compatibility.


44-46: Peer dependency specification looks appropriate.

Requiring React 18+ is appropriate since this package likely uses modern React features. This ensures compatibility with applications using the latest React versions.


47-56: Dependencies and devDependencies look good.

The package correctly uses workspace dependencies for related oRPC packages and includes zod as a development dependency for schema validation in tests.

packages/react/src/action-hooks.test-d.ts (6)

1-6: Imports and setup are correctly structured.

The imports bring in the necessary types and utilities for testing the useServerAction hook, and the setup imports shared test schemas from the contract package.


7-18: Test action setup is clear and appropriate.

The test creates an actionable client using the server object pattern, with proper input/output schemas and error handling. This provides a good foundation for testing the hook's type behavior.


19-27: Input type inference tests are comprehensive.

These tests thoroughly verify that the hook correctly infers input types, accepts valid inputs, and rejects invalid ones at compile time through TypeScript's type checking.


29-43: Required input tests validate type safety.

This test case ensures that the hook enforces non-undefined inputs when the schema requires them, which is important for type safety in application code.


45-89: Interceptor tests are thorough and check type propagation.

These tests verify that interceptors receive correctly typed inputs and can properly handle errors and data. The type expectations ensure proper type propagation throughout the interceptor chain.


91-117: Output state type tests are comprehensive.

These tests verify that the hook's state correctly reflects the type of data based on the current state (idle, pending, success, error). This ensures that consumers of the hook can safely access data based on the current state.

packages/react/src/action-hooks.test.tsx (1)

1-5: Imports look good.
No issues found in these import statements; they appear to be accurate and relevant for the test setup.

packages/react/src/server/action-form.ts (2)

9-11: Interface appears straightforward.
Declaring FormAction as a function that takes FormData and returns Promise<void> is clear and concise.


24-57: Implementation of createFormAction looks good.
Merging interceptors, deserializing form data, and invoking the client are logically structured. Error mapping is neatly handled by the custom interceptor.

packages/shared/src/interceptor.ts (2)

8-10: Enhanced type signature for next with TError is beneficial.
Adding the new generic TError and the __error object to the return type improves flexibility for detailed error handling.


17-17: Consistent Interceptor type update.
Aligning the Interceptor type definition with the changes to InterceptorOptions ensures consistency across the interceptor framework.

packages/server/src/implementer-procedure.test-d.ts (2)

1-1: Import changes reflect new architecture for actionable clients.

The imports have been updated to use ActionableClient and ActionableError types, aligning with the server action rewrite mentioned in the PR objectives.

Also applies to: 12-12


202-202: Type signature updated for actionable method.

The updated type signature properly leverages the new ActionableClient and ActionableError types, providing better type safety for error handling with proper generic type parameters.

packages/client/src/types.test-d.ts (7)

5-6: Client function signature and test setup improved.

The client function type has been properly updated to use a more flexible signature that supports optional inputs and context options.


9-9: Options type signature updated correctly.

The expected options type now properly includes the context with an optional cache property, matching the client implementation.


14-14: Function type assertion updated for clarity.

The improved function signature matches the expected usage pattern for clients with optional inputs.


18-20: Input handling tests correctly verify optional inputs.

Tests now properly verify that both string inputs and undefined inputs are accepted, which aligns with the new client function signature.


28-36: Added test case for required inputs enhances type safety verification.

This new test case ensures that non-optional inputs are properly required by the type system, which is an important aspect of the server action implementation.


75-77: Added test for output type inference.

Good addition to verify the client function returns the expected output type.


79-83: Added test for type parameter inference.

This test ensures the client's generic type parameters can be properly extracted, which is essential for tools and utilities that might need to introspect the client type.

packages/react/src/server/action-form.test.ts (6)

1-8: Test setup imports and initialization look good.

The necessary imports and beforeEach setup for resetting mocks follow testing best practices.


9-17: Test suite foundation and client setup properly configured.

The test suite correctly sets up a mock handler and creates a client with input validation using Zod, which demonstrates a real-world usage pattern.


19-28: Success case test verifies correct form data parsing.

The test correctly validates that:

  1. Form data with bracket notation is properly deserialized
  2. The handler is called with the expected input
  3. The action returns undefined as expected

This confirms the core functionality of the form action creator.


30-43: Error handling test verifies validation errors.

The test properly checks that:

  1. Invalid inputs (age > 100) are rejected
  2. The error is an ORPCError with status 400
  3. The handler is not called when validation fails

This confirms proper error handling behavior.


45-61: HTTP error fallback test verifies error translation.

Good test for verifying that server errors are properly converted to HTTP-compatible errors with appropriate status codes and digests, which is important for Server Actions integration.


63-82: Interceptor test verifies middleware functionality.

The test confirms that interceptors can be added to form actions and receive properly parsed input, which allows for customizing behavior (like redirects) after form submission.

packages/react/README.md (5)

1-46: README introduction and highlights well structured.

The README provides a comprehensive introduction to oRPC with clear badges for discoverability and a well-organized list of features.

🧰 Tools
🪛 LanguageTool

[misspelling] ~35-~35: Possible spelling mistakes found.
Context: ...tack Query (React, Vue, Solid, Svelte), Pinia Colada, and more. - Server Actions ⚡️: Ful...

(EN_MULTITOKEN_SPELLING_TWO)


47-66: Package documentation and links are complete.

All packages are properly documented with links to their npm pages, making it easy for users to discover related packages.

🧰 Tools
🪛 LanguageTool

[style] ~55-~55: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... your API or implement API contract. - [@orpc/client](https://www.npmjs.com/package/@...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/react](https://www.npmjs.com/package/@o...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~57-~57: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...with React and React Server Actions. - [@orpc/react-query](https://www.npmjs.com/pack...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~58-~58: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...test/docs/framework/react/overview). - [@orpc/vue-query](https://www.npmjs.com/packag...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~59-~59: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...latest/docs/framework/vue/overview). - [@orpc/solid-query](https://www.npmjs.com/pack...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~60-~60: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...test/docs/framework/solid/overview). - [@orpc/svelte-query](https://www.npmjs.com/pac...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...est/docs/framework/svelte/overview). - [@orpc/vue-colada](https://www.npmjs.com/packa...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[misspelling] ~61-~61: Possible spelling mistakes found.
Context: ...ge/@orpc/vue-colada): Integration with Pinia Colada. - [@or...

(EN_MULTITOKEN_SPELLING_TWO)


[style] ~62-~62: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ada](https://pinia-colada.esm.dev/). - [@orpc/openapi](https://www.npmjs.com/package/...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~63-~63: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...I specs and handle OpenAPI requests. - [@orpc/zod](https://www.npmjs.com/package/@orp...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~64-~64: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...tps://zod.dev/) doesn't support yet. - [@orpc/valibot](https://www.npmjs.com/package/...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~65-~65: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...rom Valibot. - [@orpc/arktype](https://www.npmjs.com/package/...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


67-70: @orpc/react package description is clear.

The introduction to the new React package provides a concise description of its purpose and links to more detailed documentation.


71-106: useServerAction hook documentation is comprehensive.

The example clearly demonstrates how to use the hook with a form, including error handling and type-safe error data access.


108-144: createFormAction utility documentation is thorough.

The example effectively shows:

  1. How to define a form-compatible procedure
  2. How to use interceptors for redirects
  3. How to use bracket notation for form field names
  4. How to integrate with React forms

This provides a complete guide for implementing form actions.

playgrounds/nextjs/package.json (4)

6-6: Added Turbopack to the development server

The --turbopack flag has been added to the next dev command. This will leverage Next.js's Rust-based bundler which should provide faster development experience.


15-15: Added new @orpc/react dependency

This new package adds React-specific utilities for integrating oRPC with React Server Actions. This addition aligns with the PR's objective of providing enhanced React support.


20-22: Updated Next.js and React versions

The dependencies have been updated to the latest versions:

  • Next.js from 15.1.7 to 15.2.4
  • React and React DOM from 19.0.0 to 19.1.0

These updates ensure compatibility with the new @orpc/react package.


27-28: Updated React type definitions

Type definitions for React and React DOM have been updated to match the versions of the core libraries.

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

1-4: Well-structured import statements

The import statements are well-organized, importing types from both internal and external packages. This file establishes type tests for the actionable client functionality.


5-13: Type tests for ActionableError

These tests verify that ActionableError correctly transforms error types into JSON-serializable formats with a defined flag to indicate whether the error was explicitly defined or is a generic error.


15-25: Type tests for UnactionableError

These tests ensure that UnactionableError correctly reverses the transformation of ActionableError, converting the JSON error representations back to their original Error types.


27-81: Comprehensive ActionableClient type tests

The test suite thoroughly validates that the ActionableClient type:

  1. Correctly handles both defined and undefined inputs
  2. Enforces input requirements when necessary
  3. Properly returns typed results as a tuple of [error, data]
  4. Supports type inference for error handling

The extensive test cases should ensure that users receive appropriate type checking when using the actionable clients.


83-97: ProcedureActionableClient type verification

This test confirms that the ProcedureActionableClient correctly transforms procedure definitions with input/output schemas and error maps into the appropriate ActionableClient type. This ensures compatibility between the procedure definition API and the server action API.

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

1-9: Updated imports for actionable types

The imports have been modified to include ActionableClient and ActionableError from the procedure-action module, while removing the no-longer-needed ClientRest type. This reflects the architectural changes in how server actions are implemented.


230-231: Updated return type for .actionable() method

The test now verifies that the .actionable() method returns a properly typed ActionableClient with the correct error type transformation through ActionableError. This ensures that the server action client type is correctly inferred from the procedure definition.


233-236:

Details

❓ Verification inconclusive

Added test for optional client context properties

This test case ensures that all client context properties must be optional, which is an important constraint for server actions. The test uses a deliberate type error to verify this behavior.


🏁 Script executed:

#!/bin/bash
# Verify actual implementation matches the test constraint

# Check if the implementation of actionable enforces optional context properties
ast-grep --pattern $'actionable<(.*)>\((.*?: \{
  context: (.*)
\}): (.*)' packages/server

Length of output: 91


Action Required: Verify Optional Client Context Enforcement

The test in packages/server/src/procedure-decorated.test-d.ts remains unchanged and correctly uses the deliberate type error (via @ts-expect-error --- all clientContext must be optional) to ensure client context properties are optional. However, our automated check (using the ast-grep query) did not yield any output. Please manually verify that the actual implementation of builder.actionable enforces the optionality of client context properties as expected.

  • Confirm that the actionable implementation triggers a type error when non-optional client context properties are provided.
  • Double-check that the test case in the file adequately covers this constraint.
apps/content/docs/server-action.md (6)

8-8: Clearer introduction to Server Actions

The introduction has been improved to concisely explain what React Server Actions are and how they integrate with oRPC through the .actionable modifier.


12-12: Simplified procedure definition and handler examples

The documentation now uses clearer wording and provides a more concise example of defining a procedure with .actionable. The handler has been simplified to a one-line arrow function and the error handling has been streamlined.

Also applies to: 22-27


49-57: Updated client-side example with proper error handling

The client-side example now correctly demonstrates destructuring the result tuple into [error, data], which is the actual return type of actionable procedures. The form has also been improved with a proper submit button.


64-98: Added comprehensive type-safe error handling documentation

This new section clearly explains how to work with the type-safe error objects returned from actionable procedures. The example shows how to check for defined errors and access typed error data, which is crucial for robust error handling.


130-180: Well-documented useServerAction hook

The documentation for the new useServerAction hook is clear and comprehensive. It shows:

  1. How to initialize the hook with interceptors
  2. How to execute the server action
  3. How to access status, data, and errors
  4. How to integrate with form submissions

This will be very helpful for users implementing React components that need to call server actions.


182-226: Documented createFormAction utility with real-world example

The documentation for createFormAction is excellent, providing:

  1. A clear explanation of its purpose
  2. A practical example showing form data deserialization
  3. An example of integrating with Next.js redirects
  4. Information about automatic handling of common HTTP error statuses

This utility significantly improves the developer experience when working with forms and server actions.

packages/server/src/procedure-decorated.ts (3)

15-21: New Imports Look Good

No issues with adding ProcedureActionableClient and createActionableClient imports from ./procedure-action. These imports align well with the subsequent usage in the file.


144-146: Documentation for actionable Is Clear

The updated JSDoc comment accurately reflects the method’s purpose of making the procedure compatible with server actions. Great clarity!


148-154: Confirm Intention to Drop Client Context

Switching the type parameter to Record<never, never> prevents passing any client context to actionable. If this is intentional, it’s fine; otherwise, ensure that no context is indeed required.

packages/server/src/implementer-procedure.ts (4)

9-9: New Import for ProcedureActionableClient

Importing ProcedureActionableClient is consistent with the revised types. No issues here.


78-80: Clear Documentation for Server Action Integration

The JSDoc comment and method name “actionable” communicate the method’s purpose effectively. Nice improvement.


88-88: Dropping Context in Actionable Method

Using Record<never, never> for the context parameter ensures no context is passed to server actions. Confirm that’s intentional to avoid any future friction with user-supplied context.


92-92: Updated Return Type for Actionable Procedures

Returning ProcedureActionableClient<TInputSchema, TOutputSchema, TErrorMap> aligns the interface with the new approach. Looks consistent with the design goals.

packages/server/src/procedure-action.ts (6)

1-3: Imports Are Appropriate for Actionable Client

The imports from @orpc/client and @orpc/contract are relevant for building the actionable client. No concerns here.


5-8: Well-Defined Error Types

ActionableError and UnactionableError neatly separate known and unknown error cases. This is a clear approach for standardized error handling.


9-14: Flexible Input and Output Structures

ActionableClientRest and ActionableClientResult expand the RPC call’s flexibility with optional inputs and structured success/error returns. Nicely done.


15-17: Concise ActionableClient Interface

Using a callable interface for handling an RPC request and returning a promise with defined success/error tuples is a clean design pattern.


19-28: ProcedureActionableClient Type Is Consistent

Extending ActionableClient with schema-driven inputs/outputs and mapped errors ensures type safety across procedure boundaries.


29-42: Robust createActionableClient Implementation

Transforming a regular client into an actionable client by returning a tuple of [error, data] on each call is intuitive for server actions. Good job handling error conversion with toORPCError.

Comment thread packages/react/src/action-hooks.test.tsx Outdated
Comment thread packages/react/src/action-hooks.test.tsx Outdated
Comment thread packages/react/src/action-hooks.test.tsx Outdated
Comment thread packages/react/src/action-hooks.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 29, 2025

Codecov Report

Attention: Patch coverage is 98.41270% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/react/src/hooks/index.ts 0.00% 0 Missing and 1 partial ⚠️
packages/react/src/index.ts 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/react/src/action-hooks.test.tsx (3)

50-52: Use awaited act for reset operation for consistency.

While reset itself isn't async, maintaining consistent use of awaited act throughout your tests prevents potential future issues if the implementation changes.

-act(() => {
-  result.current.reset()
-})
+await act(async () => {
+  result.current.reset()
+})

99-101: Apply consistent awaited act pattern for reset operation.

For consistency across all test cases.

-act(() => {
-  result.current.reset()
-})
+await act(async () => {
+  result.current.reset()
+})

1-153: Add test for concurrent executions and cancellation scenarios.

The current tests verify basic success, error, and interceptor cases, but don't test how the hook behaves when multiple actions are triggered in rapid succession or when component unmounts during a pending action.

Consider adding these test cases:

  1. A test case that triggers multiple executions in succession to verify proper state handling
  2. A test that unmounts the component during a pending action to ensure no memory leaks

Example for concurrent executions:

it('handles concurrent executions correctly', async () => {
  const { result } = renderHook(() => useServerAction(action))
  
  // Start first execution
  const promise1 = result.current.execute({ input: 123 })
  
  // Second execution should supersede the first
  await act(async () => {
    await result.current.execute({ input: 456 })
  })
  
  // Verify only the second execution's result is reflected
  expect(result.current.status).toBe('success')
  expect(result.current.input).toEqual({ input: 456 })
  expect(result.current.data).toEqual({ output: '456' })
  
  // First promise should still resolve
  await promise1
})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9050067 and 7ee8e30.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • apps/content/package.json (2 hunks)
  • packages/react-query/package.json (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/src/action-hooks.test.tsx (1 hunks)
  • playgrounds/nextjs/package.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/content/package.json
  • packages/react/package.json
  • playgrounds/nextjs/package.json
🧰 Additional context used
🧬 Code Definitions (1)
packages/react/src/action-hooks.test.tsx (1)
packages/react/src/action-hooks.ts (1)
  • useServerAction (84-154)
🔇 Additional comments (3)
packages/react/src/action-hooks.test.tsx (3)

28-31: Use awaited act for asynchronous operations to prevent test timing issues.

The act function should be awaited when dealing with async state updates to ensure all updates are processed before assertions. This prevents potential test flakiness.

-act(() => {
-  result.current.execute({ input: 123 })
-})
+await act(async () => {
+  await result.current.execute({ input: 123 })
+})
#!/bin/bash
# Check for potential async operation warnings in test files
rg "act\(\(\) =>" -A 3 --glob "*.test.{tsx,ts}" | rg "await|Promise|async"

76-79: Use awaited act for async execute operation to prevent test failures.

Similar to the first test case, this act call should be awaited as it's triggering async state updates. This was specifically highlighted in previous reviews as causing CI failures.

-act(() => {
-  // @ts-expect-error --- invalid input
-  result.current.execute({ input: 'invalid' })
-})
+await act(async () => {
+  // @ts-expect-error --- invalid input
+  await result.current.execute({ input: 'invalid' })
+})

126-132: Use awaited act for async execute with interceptors to prevent test failures.

This async operation needs to be awaited, as the previous review comments indicated failures accessing properties of null at this point in the tests.

-act(() => {
-  result.current.execute({ input: 123 }, {
-    interceptors: [
-      executeInterceptor,
-    ],
-  })
-})
+await act(async () => {
+  await result.current.execute({ input: 123 }, {
+    interceptors: [
+      executeInterceptor,
+    ],
+  })
+})

Comment thread packages/react-query/package.json
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 (4)
packages/react/src/hooks/action-hooks.test-d.ts (1)

29-29: Fix minor typo in the test description.

"undefindable" should be "undefined" or "non-undefined" for clarity.

- it('require non-undefindable input ', () => {
+ it('require non-undefined input ', () => {
packages/react/src/action-form.ts (1)

52-55: Consider returning the client result for better form action handling.

By returning the result of client, the caller can directly handle any success or error states.

return async (form) => {
  const input = bracketNotation.deserialize([...form])
- await client(input as any)
+ return await client(input as any)
}
packages/react/src/action-form.test.ts (2)

30-43: Consider awaiting the rejected promise for reliability.

When checking for errors using expect(action(form)).rejects.toSatisfy(...), it’s generally safer to either await or return the promise to ensure the test completes only after the assertion passes or fails, preventing false positives if the test ends prematurely.

-it('on error', async () => {
-  expect(action(form)).rejects.toSatisfy((error) => {
+it('on error', () => {
+  return expect(action(form)).rejects.toSatisfy((error) => {
     // ...
  })
})

45-61: Align test structure for "on fallback-able http next error" with best practices.

Similarly, consider returning or awaiting the promise in this test. It ensures that the testing framework properly waits for the asynchronous rejection and the subsequent assertions.

-it('on fallback-able http next error', async () => {
-  expect(action(form)).rejects.toSatisfy((error) => {
+it('on fallback-able http next error', () => {
+  return expect(action(form)).rejects.toSatisfy((error) => {
     // ...
  })
})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e2c734 and 927dd64.

📒 Files selected for processing (11)
  • apps/content/docs/server-action.md (2 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/src/action-form.test.ts (1 hunks)
  • packages/react/src/action-form.ts (1 hunks)
  • packages/react/src/hooks/action-hooks.test-d.ts (1 hunks)
  • packages/react/src/hooks/action-hooks.test.tsx (1 hunks)
  • packages/react/src/hooks/action-hooks.ts (1 hunks)
  • packages/react/src/hooks/index.ts (1 hunks)
  • packages/react/src/index.ts (1 hunks)
  • playgrounds/nextjs/src/app/actions.ts (2 hunks)
  • playgrounds/nextjs/src/app/orpc-server-action.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/react/src/hooks/index.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/react/src/index.ts
  • packages/react/package.json
  • playgrounds/nextjs/src/app/orpc-server-action.tsx
  • playgrounds/nextjs/src/app/actions.ts
  • apps/content/docs/server-action.md
🧰 Additional context used
🧬 Code Definitions (2)
packages/react/src/hooks/action-hooks.test-d.ts (1)
packages/react/src/hooks/action-hooks.ts (1)
  • useServerAction (84-154)
packages/react/src/action-form.test.ts (1)
packages/react/src/action-form.ts (1)
  • createFormAction (24-56)
🔇 Additional comments (9)
packages/react/src/hooks/action-hooks.test.tsx (2)

12-47: Verify numeric vs. string mismatch in output.

Line 12 returns a number (Number(input?.input ?? 0)), while line 47 expects the output as a string. Confirm this is intentional or adjust the handler or test to align with the desired output type.


64-153: Tests for error-handling and interceptors look good.

The logic for transitioning between states, verifying error presence, and interceptors invocation is well-structured.

packages/react/src/action-form.test.ts (2)

9-11: Tests are well-structured and clearly named.

The createFormAction test suite is well-organized, making it straightforward to identify the exact behavior being tested.


63-83: Great test coverage for interceptors.

Verifying that the interceptor is called, and that it can manipulate the action’s input/output, confirms correct integration. The test coverage here looks good.

packages/react/src/hooks/action-hooks.ts (5)

1-6: Imports are consistent and minimal.

All imported symbols appear relevant to the hook’s logic. Keeping imports lean helps maintain readability and reduces build times.


7-10: Interface naming is clear.

UseServerActionOptions is accurately named to convey its purpose as optional configuration for the hook.


30-70: Clean separation of result states.

Defining separate result interfaces (Idle, Pending, Success, Error) is a solid approach to strongly typed “state machine”-like behavior, making the hook usage more intuitive for consumers.


72-83: Initial state clarity.

Initializing state as a constant ensures consistent defaults for the hook. This helps prevent subtle bugs from uninitialized fields.


84-154:

Details

❓ Verification inconclusive

Potential concurrency edge case when calling execute multiple times concurrently.

Currently, if execute is called while the hook is already in the pending state, the existing request state is overwritten. This could be intentional but might lead to race conditions in real-world usage. Consider additional checks or a queue mechanism if multiple simultaneous calls need special handling.

Would you like to verify if the consumer code triggers multiple execute calls concurrently? If so, consider the approach below.


🏁 Script executed:

#!/bin/bash
# Attempt to locate concurrent usage of `execute` calls in the codebase.
rg -A 5 'useServerAction' 

Length of output: 7904


Action: Address potential race conditions in concurrent execute calls

After reviewing the tests and usage examples, it appears that current consumer calls to execute (as seen in both TS and TSX test files) are performed sequentially. However, the implementation of useServerAction lacks safeguards for handling concurrent invocations—subsequent calls will overwrite the state of an ongoing request. If concurrent calls are ever issued in a production environment, this could result in unpredictable behavior or race conditions.

  • Concern: The hook resets its state on every execute call without checking if a previous call is still pending.
  • Recommendation: Consider adding a concurrency check or a queuing mechanism (or cancellation of previous pending calls) if multiple simultaneous executions are a valid use case. Alternatively, if the sequential behavior is intentional, update the documentation to clearly warn users of this limitation.

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