




Planted:
Status: seed
Intended Audience: Software engineers
An investigation into using AI to migrate CSS from CSS Modules to StyleX.
My team received new requirements, a business decision was made to migrate from CSS modules to StyleX. We own multiple projects so we picked one as a test case to assess how much effort a migration will require. It's a 2-page microsite with a form, made in React.
The codebase has three versions of this site: v1, v2, and v3. Each builds on the previous. v3 has new components and components imported from v1, v2 and a shared directory. v3 is live and the only version we want to migrate. Before AI, I would use a codemodAn automated script that refactors your codebase by programmatically parsing, changing, and rewriting your source code. but this as an opportunity to assess the latest AI capabilities and see how well it could handle this task.
Agent:
Before starting the migration I made the codebase agent-friendly by adding any missing AGENT.mdA standard Markdown file placed in a code repository to give AI coding agents project-specific context, rules, and instructions. files to key directories. This is a best practice for any codebase using AI.
Next, I prompted the agent to write a specA clear, structured description of what software should do, its constraints, and how it behaves. to narrow the gap between my intention and the AI's actions.
The AI landscape changes fast making it difficult to know how much information I need to provide.
Therefore, instead of guessing, I prompt the simplest, high-level intent: Write a spec to migrate v3 from CSS modules to StyleX.
The generated draft reveals what information I need to provide to steer the AI towards what I want.
The following are the notable parts.
The spec detailed v1, v2 and a shared directory will be affected by the migration because of imported components. This information is useful because I want to restrict the scope as much as possible. Reprompting added the following to the spec:
_v2 to the component's name and add a deprecation comment to the original component.A consistent weakness with each generation of AI is communicating technical information. This is apparent with the spec, being overly complex and the way it communicates can be a poor fit for what it's communicating. For example, the spec has a hard cases section. A list of CSS rules that don't easily translate to StyleX and details about how the migration will handle each one. These are communicated as prose but would be easier to understand in a before / after table with examples of code.
Prose: Desktop menu sibling/state selectors. For the divider between items, compute “show divider” in the loop and apply a variant.
Table:
| CSS | StyleX |
|---|---|
| .item + .item // menu divider | Decide in JS whether this item needs a divider; add a divider style when it does |
Reprompting specifying how to display information improves results. Results can be expanded beyond text to diagrams, sandboxes and 3D models.
The plan for migrating theming was bad. It detailed creating some complex solution combining the current solution (CSS variables) with StyleX style objects. This surprised me because:
Reprompting and providing a link to the StyleX theme documentation improved the plan.
The plan to migrate some animations was also bad.
Some animations are linked to scroll position.
The animation moving forward or backward depending on the scroll position.
To avoid performance problems caused by React component re-rendering, the current code uses CSS variables manipulated by JavaScript within a useEffect.
This spec's initial plan would introduce this problem.
Because AI is probabilistic, not deterministic, the most important thing when working with it is verification, confirming what the AI did matches my intention. The spec did a good job at this, listing four checks that run for every PR:
git diff to confirm only changes to the v3 and shared directories are made.I was surprised the spec didn't detail agent architecture. When queried, it stated it would use a single-agent working sequentially, producing a chain of 26 PRs. This is inefficient considering part of the migration involves migrating multiple react components. Work that can be done in parallel by multiple agents. Architecture patterns:
Re-prompting added an agent architecture section changing 26 sequential PRs to 4 PR waves.
AGENTS.md.The following is issues that came up during implementation.
A failing visreg exposed a failed migration. StyleX flattens the cascade to atomic classes so a rule that used to win by CSS specificity stops winning.
Original CSS:
:root { --padding: 48px; }@media (max-width: 900px) { :root { --padding: 32px; } }@media (max-width: 600px) { :root { --padding: 24px; } }
Migrated CSS (StyleX):
paddingXSection: {default: '48px',belowMedium: '32px', // under 900belowSmall: '24px', // under 600}
Problem (StyleX compiled):
Media blocks sorted alphabetically (600 before 900), so now padding: 24px will never be applied.
:root { --padding: 48px; }@media (max-width: 600px) { :root { --padding: 24px; } }@media (max-width: 900px) { :root { --padding: 32px; } }
Solution (StyleX):
paddingXSection: {default: '48px',belowMedium: {default: '32px',belowSmall: '24px',},}
When a wave completed, the chat would prompt me for human review and raise issues that need a decision. This thread started to get long and I became concerned about context failure. When you prompt AI, the chat history gets sent along with your latest prompt. All history is context. Context can fail, causing degraded AI results in four ways:
To avoid this, after wave B I modified the spec: When a wave completes, add handoff notes to the spec so a new chat can continue the work.
When starting a new wave, I would open a new chat and prompt the AI to continue based on the handoff notes.
There was one instance where verification failed. The error was caught by human review. During a wave, changes were made to CSS in v1's directory even though the spec explicitly stated not to modify files outside of the v3 and shared directory. There was also a verification step to check this (see above). AI is probabilistic, not deterministic. The mistake I made was allowing AI to manage verification. Handing verification steps to human control would have caught the error.
https://cursor.com/dashboard/usage)Have any feedback about this note or just want to comment on the state of the economy?

