Skip to main content

React Server Components Migration Patterns

Migrate client-side React to Server Components with clean server/client boundaries, Suspense, and a measurable bundle-size reduction.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are an expert React architect specializing in Server Components. Help me migrate a SaaS dashboard application to leverage React Server Components effectively.

Step 1: Audit the existing component tree in the src/components directory and classify every component as either a server-component candidate (no hooks, no browser APIs, data-fetching only) or a client-component requirement (uses useState, useEffect, event handlers, or browser APIs). Present results in a table with columns: Component | Current Type | Recommended Type | Reason.

Step 2: Design a clear server/client boundary strategy for the product catalog feature area. Identify which components should remain client-side using the "use client" directive, and which can become server components that fetch data directly. Ensure the boundary minimizes the client bundle size by at least 30%.

Step 3: Create a data-fetching migration plan that replaces existing useEffect + fetch patterns with direct async server component data fetching. For each endpoint in /api/v1, show the before/after code pattern and explain how to handle loading states with Suspense boundaries.

Step 4: Implement a shared state strategy where server components pass serializable props to client components. Design the prop interfaces to avoid passing non-serializable values (functions, class instances) across the boundary.

Step 5: Set up proper error boundaries using the error.tsx convention for each route segment. Ensure server-side errors are caught gracefully and client components have their own ErrorBoundary wrappers.

Step 6: Write a performance validation checklist that measures bundle size reduction, Time to First Byte improvement, and Largest Contentful Paint changes after migration. Target a minimum 30% reduction in client JavaScript.

What this prompt does

This prompt casts the AI as a React Server Components architect and walks it through migrating a [project_type] app to RSC. It starts by auditing the component tree in [source_directory], classifying every component as a server-component candidate or a client-component requirement, then designs a clean server/client boundary for [primary_feature] that cuts the client bundle by at least [target_reduction]. The classification table is where most teams trip, so the prompt front-loads it.

The structure works because RSC migrations fail at the boundary. After classification, it replaces useEffect + fetch patterns with direct async server-component fetching for each endpoint under [api_base_url], designs serializable prop interfaces so non-serializable values never cross the boundary, sets up error.tsx error boundaries per route segment, and ends with a performance checklist measuring bundle size, TTFB, and LCP against the [target_reduction] goal. That final measurement keeps the migration honest. By converting useEffect + fetch patterns into direct async server-component fetching for each endpoint under [api_base_url], it removes a whole class of client-side loading code and moves data fetching closer to the source. The serializable-prop interface design is deliberate, because functions and class instances cannot cross the server/client boundary, and getting that wrong is one of the most common ways an RSC migration breaks. Pairing Suspense with error.tsx boundaries per route segment means a slow or failed server fetch degrades gracefully instead of blanking the page.

When to use it

  • You are moving a client-heavy React dashboard or app onto Server Components
  • You need a component-by-component classification of server vs client
  • You want to replace useEffect data fetching with async server components
  • You keep accidentally passing functions or class instances across the boundary
  • You need route-segment error boundaries via the error.tsx convention
  • You want measured proof that the client bundle actually shrank

Example output

The AI returns a classification table (Component, Current Type, Recommended Type, Reason), a server/client boundary strategy for [primary_feature] with "use client" placement, before/after code for converting useEffect + fetch to async server-component fetching across [api_base_url], serializable prop interface designs, error.tsx error boundaries per route segment with client-side ErrorBoundary wrappers, and a performance validation checklist measuring bundle reduction, TTFB, and LCP toward [target_reduction].

Pro tips

  • Trust the classification table — anything using hooks, event handlers, or browser APIs must stay a client component
  • Design serializable props deliberately; functions and class instances cannot cross the server/client boundary
  • Push "use client" as far down the tree as possible so the smallest subtree ships to the browser
  • Convert data fetching one endpoint at a time under [api_base_url] so a regression is easy to isolate
  • Measure the bundle before and after against [target_reduction]; an unmeasured migration tends to drift
  • Pair Suspense boundaries with error boundaries so a slow or failed server fetch never blanks the route

Frequently Asked Questions

How does it decide which components become server components?
The audit classifies each component by whether it uses hooks, event handlers, or browser APIs. Components doing only data fetching with none of those become server-component candidates, while anything stateful or interactive stays a client component marked with `"use client"`.
Why does the serializable-prop step matter so much?
Server components can only pass serializable values to client components, so functions, class instances, and similar non-serializable values break the boundary. The prompt designs prop interfaces to avoid these, which is one of the most common ways RSC migrations fail in practice.
Does it actually verify the bundle got smaller?
Yes. The final step is a performance checklist measuring client JavaScript reduction, TTFB, and LCP before and after, targeting at least `[target_reduction]`. Measuring keeps the migration honest rather than assuming the boundary changes helped.
How are server-side errors handled during the migration?
It sets up `error.tsx` error boundaries for each route segment so server-side errors are caught gracefully, and pairs them with client-side ErrorBoundary wrappers. This prevents a failed server fetch from taking down the whole route.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in React & Next.js Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support