Investigating whether server functions in event handlers is intended behavior
The issue questions whether server functions working in event handler props is intended behavior, showing inconsistent results across frameworks. Needs investigation into React's design intentions and potential documentation updates.
This isn't a bug report - the behaviour described below works correctly. I'm raising this to ask whether it's intended/stable behaviour and whether it should be documented.
React version: 19
"use client" directive)"use server") inside itonClick, onMouseEnter)Link to code example:
// This is a Server Component (no "use client" directive)
export default function Page() {
async function handleClick() {
"use server";
console.log("click");
}
async function handleHover() {
"use server";
console.log("hovering...");
}
return (
<div>
<button onClick={handleClick}>Click me</button>
<h2 onMouseEnter={handleHover}>Hover me</h2>
</div>
);
}
Note: Passing the event object to the server function (e.g., onClick={(e) => handleClick(e)}) errors out, presumably because the event cannot be serialized. The bare function reference works fine.
| Framework | React | Result |
|---|---|---|
| Next.js 16 | 19 | ✅ Works |
| Next.js 15.5.9 | 19 | ✅ Works |
| Next.js 14.2.35 | 18 | ❌ Crashes: "Only plain objects, and a few built-ins, can be passed to Server Actions" |
| Waku | 19 | ✅ Works (independently confirmed) |
The fact that this works on both Next.js and Waku suggests it's a React-level behavio
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!