0
0
NextJSframework~8 mins

Why server actions simplify mutations in NextJS - Performance Evidence

Choose your learning style9 modes available
Performance: Why server actions simplify mutations
MEDIUM IMPACT
This concept affects interaction responsiveness and reduces client-side bundle size by moving mutation logic to the server.
Updating data on user interaction in a Next.js app
NextJS
'use server';

export async function increment() {
  // Server-side mutation logic
  await db.incrementCounter();
}

export default function Counter() {
  return <form action={increment}>
    <button type="submit">Increment</button>
  </form>;
}
Mutation runs on the server, removing mutation code from client bundle and reducing network overhead, improving input responsiveness.
📈 Performance GainSaves ~5-10kb client bundle; reduces network requests; improves INP by handling mutation server-side
Updating data on user interaction in a Next.js app
NextJS
import { useState } from 'react';

export default function Counter() {
  const [count, setCount] = useState(0);

  async function increment() {
    // Client-side mutation with fetch
    await fetch('/api/increment', { method: 'POST' });
    setCount(count + 1);
  }

  return <button onClick={increment}>Count: {count}</button>;
}
Mutation logic runs on the client and requires extra client-side code and API calls, increasing bundle size and causing slower input response.
📉 Performance CostAdds ~5-10kb to client bundle; triggers multiple network requests; blocks input responsiveness during fetch
Performance Comparison
PatternClient Bundle SizeNetwork RequestsInput ResponsivenessVerdict
Client-side mutation with fetchLarger (+5-10kb)Multiple requestsSlower due to fetch wait[X] Bad
Server actions for mutationsSmaller (saves 5-10kb)Fewer requests, form submitFaster input response[OK] Good
Rendering Pipeline
Server actions move mutation logic from client to server, reducing client-side JavaScript parsing and execution. This reduces the time spent in scripting and network requests on the client, improving interaction responsiveness.
Scripting
Network
Input Handling
⚠️ BottleneckClient-side scripting and network latency during mutation calls
Core Web Vital Affected
INP
This concept affects interaction responsiveness and reduces client-side bundle size by moving mutation logic to the server.
Optimization Tips
1Move mutation logic to server actions to reduce client bundle size.
2Server actions reduce network requests and improve input responsiveness.
3Improved input responsiveness directly benefits the INP Core Web Vital.
Performance Quiz - 3 Questions
Test your performance knowledge
How do server actions improve input responsiveness compared to client-side mutations?
ABy increasing client bundle size to handle mutations faster
BBy moving mutation logic to the server, reducing client scripting and network overhead
CBy caching mutation results on the client
DBy delaying mutation until after page load
DevTools: Performance
How to check: Record a user interaction that triggers a mutation. Look at scripting time and network requests related to mutation.
What to look for: Long scripting blocks and multiple fetch requests indicate client-side mutation; minimal scripting and fewer requests indicate server actions.