Demo, all content is generated
Question

Cursor keeps putting everything in one 1400-line page.tsx, how do I split it safely

Open · 692 views · asked by valentina_s · edited

My main page is 1400 lines now. Every feature I asked for went into the same file. When I ask Cursor to "split this into components" it rewrites half of it and things break (filters stop working, a modal doesn't open). I reverted twice.

How do real developers approach this? I don't want to break my app again.

What I’ve tried

Asked for a full split twice (both reverted), asked for 'just extract the header' which worked but it also renamed state variables.

Comment
Following, I have a 2000-line one. nomvula_b · edited

3 answers

katja_s · edited

Small moves, one per commit, and make the AI move code instead of writing code.

  1. Commit what you have.
  2. Pick the most self-contained piece (usually something with no state, like the footer or a card).
  3. Prompt: "Move the JSX for the pricing card verbatim into components/pricing-card.tsx. Pass what it needs as props. Do not rename, restyle or change any logic."
  4. Click through the app. Commit.
  5. Repeat.

Stateful pieces last. When you get to those, pass the state and setter down as props first. Clean it up later, once everything lives in its own file.

It's boring and takes an evening. That's the point.

Comment
Did 6 extractions tonight, nothing broke. Page is at 900 lines. valentina_s · edited
The 'do not rename' line is everything. The models love renaming. ingrid_h · edited
mei_lin · edited

On top of that, since this is App Router: split by where the code needs to run. The data loading can go to the server page. Only the interactive parts (filters, modal) need "use client":

app/page.tsx              → server: fetch data, render layout
components/filters.tsx    → client: useState for filters
components/results.tsx    → client or server, depending on interactivity

You'll probably find half the 1400 lines don't need to be client code at all.

Comment
Ok this one I'll do after the extraction, one thing at a time :) valentina_s · edited
sanne_dev · edited

Before any moving: ask the agent for a map, no code. 'List the sections of this file, which state each one reads and writes.' That list tells you which pieces are safe to extract first (the ones that touch no state).

Comment