Skip to content

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Sep 26, 2025

Description

todo

  • test with react-router client routes

example

  • client.tsx
'use client'

import React from 'react'

export function ClientCounter() {
  const [count, setCount] = React.useState(0)

  function someFn() {
    "use server";
    console.log("foo");
  }

  return (
    <button onClick={() => setCount((count) => count + 1)}>
      Client Counter: {count}
    </button>
  )
}

This code will cause a build error:

error during build:
[rsc:use-client] [plugin rsc:use-client] src/client.tsx (7:4): 'use server' directive is not allowed within 'use client'
file: /home/hiroshi/code/others/vite-plugin-react/packages/plugin-rsc/examples/starter/src/client.tsx:7:4

5:   const [count, setCount] = React.useState(0);
6:   function someFn() {
7:     "use server";
       ^
8:     console.log("foo");
9:   }

example (react router client module)

  • route.tsx
function serverFnInsideClienRoute() {
  "use server";
  console.log("nooo");
}

export default function Index() {
  return (
    <div>
      <form action={serverFnInsideClienRoute}>foo</form>
    </div>
  );
}
  • build error
vite v7.1.6 building SSR bundle for production...
🧪 Using React Router's RSC Framework Mode (experimental)
✓ 33 modules transformed.
✗ Build failed in 221ms
[rsc:use-client] [plugin rsc:use-client] app/routes/_index/route.tsx?client-route-module (3:2): 'use server' directive is not allowed inside 'use client'
file: /home/hiroshi/Downloads/github-mu2rn18z-rvf27n9w/app/routes/_index/route.tsx?client-route-module:3:2

1: "use client";import { jsx } from "react/jsx-runtime";
2: function serverFnInsideClienRoute() {
3:   "use server";
     ^
4: 
5:   console.log("nooo");

@hi-ogawa hi-ogawa marked this pull request as ready for review September 26, 2025 02:26
@hi-ogawa hi-ogawa added the trigger: preview Trigger pkg.pr.new label Sep 26, 2025
Copy link

pkg-pr-new bot commented Sep 26, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@vitejs/plugin-react@884
npm i https://pkg.pr.new/@vitejs/plugin-react-oxc@884
npm i https://pkg.pr.new/@vitejs/plugin-rsc@884
npm i https://pkg.pr.new/@vitejs/plugin-react-swc@884

commit: c48caaa

@hi-ogawa hi-ogawa merged commit 5bc3f79 into main Sep 26, 2025
26 checks passed
@hi-ogawa hi-ogawa deleted the 09-26-fix_rsc_reject_inline_use_server_inside_use_client_module branch September 26, 2025 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
trigger: preview Trigger pkg.pr.new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reject inline "use server" inside client boundary
1 participant