Cursorcursorintermediate
Refactor to React Server Components (Cursor Prompt)
Cursor prompt to refactor client components to React Server Components for better performance.
What you'll get
Refactored components using React Server Components with client islands for interactivity and better performance.
The Prompt
Refactor client components to React Server Components (RSC) in this Next.js app. STEPS: 1. Audit all components with 'use client' directive. For each, determine if it actually needs client-side features (hooks, event handlers, browser APIs, context). 2. For each component that can become a Server Component: a. Remove 'use client' directive b. Move data fetching from useEffect/TanStack Query into the component body (direct await) c. Replace useState for server data with props passed from the server d. Move event handlers into a smaller client component child 3. Apply the "Island Architecture" pattern: Server Components as the default, with small Client Component islands for interactivity. 4. Extract interactive parts into separate client components: - SearchInput (client) inside SearchPage (server) - LikeButton (client) inside PostCard (server) - FormComponent (client) inside FormPage (server) 5. Move data fetching to the highest server component possible. Pass data down as props. 6. Convert TanStack Query calls to direct Supabase queries in Server Components where the data doesn't need client-side caching or real-time updates. PATTERNS TO FOLLOW: - Server Components fetch data, Client Components handle interactivity - Use Suspense boundaries around async Server Components with loading.tsx fallbacks - Pass serializable props only (no functions, classes, or Dates) from Server to Client Components DO NOT: - Remove 'use client' from components that use hooks, refs, or event handlers - Break existing functionality — test each refactored component - Remove TanStack Query for data that needs client-side polling or real-time updates
Replace these variables
| Variable | Replace with |
|---|---|
| [TARGET_COMPONENTS] | Components to prioritize for refactoring |
Tips for best results
Start with data-heavy pages (dashboards, listings) — they benefit most from RSC refactoring.
Create a checklist of each component's 'use client' reasons before refactoring.
Follow-up prompts
Add streaming
Add streaming SSR with Suspense boundaries and loading.tsx files for each route segment to progressively render the page.