# Add Dark Mode to a SolidJS App

Yes. An agent adds a persisted theme signal, a data-theme stylesheet that overrides your CDN theme, a toggle in the navbar, and opens a PR with screenshots.

[Run this on Rush](https://cloud.getrush.ai/run/add-dark-mode/solidjs/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads how the app is styled before it writes a line of CSS. In an app like solidjs/solid-realworld, `package.json` depends on `solid-js` and `marked` only, and builds with Rollup 2 through `babel-preset-solid` (`rollup.config.js`), with `npm start` serving `public/` and `npm run build` writing the bundle there. `public/index.html` loads every style from outside the repository: Ionicons from a CDN, Google Fonts, and the Bootstrap 4 theme at `demo.productionready.io/main.css`, plus one inline rule, `body{min-height: 101vh;}`. There is no stylesheet in `src/`, so dark mode cannot be a change to existing CSS; it has to be an override layered on top of the CDN theme.

The state lives in `src/store/index.js`: a `Provider` that builds one `createStore` with `token` read from `localStorage.getItem("jwt")`, `appName`, the page counters, and getters backed by the `create*` modules; `src/store/createCommon.js` is the pattern the agent follows, with a `createEffect` that writes `token` to `localStorage` and an action added to the shared `actions` object. `src/components/NavBar.js` renders `nav.navbar.navbar-light` with the links, switching on `store.currentUser`. `src/index.js` renders `Provider` and `App` into `document.body`. One more file matters: `rollup.config.js` uses `rollup-plugin-delete` with `targets: ["public/*", "!public/index.html"]`, which would delete any stylesheet dropped into `public/` on the next build.

The agent adds `src/store/createTheme.js`, which reads `localStorage.getItem("theme")`, falls back to `matchMedia("(prefers-color-scheme: dark)")`, exposes `theme` on the store and `toggleTheme` on `actions`, and runs a `createEffect` that sets `document.documentElement.dataset.theme` and writes the choice back to `localStorage`, the same shape as the token effect. In `NavBar.js` it adds one `nav-item` with a button whose glyph comes from the Ionicons set the page already loads, shown to signed-in and signed-out visitors alike. The styles go in `public/theme.css`: CSS custom properties for background, text, border and card colours on `:root`, their dark values under `[data-theme="dark"]`, and rules that apply them to `body`, `.navbar`, `.article-preview`, `.tag-default`, `.form-control`, the `.home-page .banner` block and the article body, each scoped to the selectors `main.css` uses so that specificity wins without `!important`. `index.html` links it after `main.css`, carries a two-line inline script that applies the stored theme before the bundle loads so there is no flash of the light theme, and `rollup.config.js` gets `"!public/theme.css"` added to the delete exclusions.

Then it proves the change. `npm install` and `npm run build` run in the sandbox; the agent serves `public/`, opens the app in the sandbox browser, toggles the theme on the home page, an article page and the settings form, and takes a screenshot of each in both themes for the pull request. It reloads to show the choice persists, and checks that `localStorage` holds `theme` beside `jwt`. The repository has no tests (`"test": "test"` in `package.json`), so the screenshots and the build log are the evidence.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add dark mode to this SolidJS app. Read package.json, rollup.config.js, public/index.html, src/index.js, src/store/index.js and src/components/NavBar.js first, and find where the styles come from. Add a theme to the store following the pattern the other store modules use, persisted to localStorage and defaulting to the system preference, with a toggle action and a data-theme attribute on the document element. Add a toggle to the navbar. Write a stylesheet of CSS custom properties with dark values that overrides the existing theme without !important, apply the stored theme before the bundle loads so the light theme does not flash, and make sure the build does not delete the new stylesheet. Build the app, open it in the browser, screenshot the home, article and settings pages in both themes, and open a pull request with the screenshots. Do not replace the existing stylesheet.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch adding `src/store/createTheme.js` and `public/theme.css`, and editing `src/store/index.js`, `src/components/NavBar.js`, `public/index.html` and `rollup.config.js`. The description carries six screenshots from the sandbox browser (three pages, two themes), explains the `data-theme` attribute and the inline script, and notes the one-line Rollup change and why it is needed.

The run's record keeps the `npm run build` output and every page the browser opened, so a reviewer can see the toggle was exercised rather than described.

Before merging, a reviewer checks the dark palette against the brand, looks at the article body colours where `marked` renders user Markdown, and decides whether the toggle belongs in the navbar for everyone or on the settings page for signed-in users only.

## Run it on every Linear issue labelled design

In the console, an automation in the Project that has the repository, with a `linear` trigger on `linear.issue.labeled` and `config.labels` set to `design`, starts one run per issue that asks for a theme or styling change, with the issue text added after the prompt. The run reads the issue, makes the change, screenshots it and opens a pull request that links the issue.

From your own server, the same work is one `POST /o/{org}/sessions` with this body and the repository in `resources`; a webhook on the API key reports `run.completed` with the `session_url` to read the pull request and its screenshots.

## Why run it on Rush?

Dark mode in an app whose theme comes from a CDN is mostly archaeology: finding every selector `main.css` colours, picking overrides that win on specificity, and noticing that the build script deletes new files in `public/`. An agent with the repository and a browser in front of it does that reading, then shows the result as screenshots instead of asking a reviewer to pull the branch and click around.

The sandbox builds the app with the project's own Rollup setup and keeps the log and the pages it visited in the record. Several apps, or several pages of one app, can be themed at the same time in separate sandboxes.

## Frequently asked questions

### Why not edit the existing stylesheet?

There is none in the repository; `main.css` is loaded from a CDN. An override stylesheet keyed on `data-theme` leaves the upstream theme untouched and works with any later version of it. The prompt forbids replacing the existing stylesheet for the same reason.

### Will the page flash light before going dark?

No. A two-line inline script in `index.html` reads `localStorage` and sets `data-theme` before the module bundle loads, and the store's effect takes over from there. The screenshots after a reload show the dark theme from first paint.

### Does it respect the operating system preference?

Yes, as the default when nothing is stored: `createTheme.js` checks `prefers-color-scheme`. Once the visitor toggles, their choice in `localStorage` wins, like the `jwt` token the store already persists.

### What about the icons and fonts from the CDN?

The toggle uses a glyph from the Ionicons set `index.html` already loads, and the fonts do not change. If the icon set is later replaced, the toggle is one element in `NavBar.js` to update.

## More SolidJS jobs

- [Add Dependabot to a SolidJS App](https://getrush.ai/run/add-dependabot/solidjs/)
- [Add Error Boundaries to a SolidJS App](https://getrush.ai/run/add-error-boundaries/solidjs/)
- [Add ESLint to a SolidJS App](https://getrush.ai/run/add-eslint/solidjs/)

## The same job on other stacks

- [Add Dark Mode to Sphinx Docs on the Read the Docs Theme](https://getrush.ai/run/add-dark-mode/sphinx/)
- [Add Dark Mode to a SvelteKit App](https://getrush.ai/run/add-dark-mode/sveltekit/)
- [Add Dark Mode to a Symfony App](https://getrush.ai/run/add-dark-mode/symfony/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
