All jobs

Add Dark Mode to a Blazor Web App

Yes. An agent adds a dark mode to your Blazor Web App with Bootstrap 5.3 color modes, a toggle that remembers the choice, no flash on load, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how the app is styled before adding a theme. In an app like the BlazorWebAppMovies sample in dotnet/blazor-samples, Components/App.razor loads lib/bootstrap/dist/css/bootstrap.min.css, app.css and the scoped BlazorWebAppMovies.styles.css through @Assets, and the bundled Bootstrap header reads v5.3.3, the first release with data-bs-theme color modes, so the dark palette is already on disk and unused. Components/Layout/MainLayout.razor.css hardcodes .top-row to #f7f7f7 with a #d6d5d5 border, NavMenu.razor uses navbar-dark on a sidebar whose gradient is fixed in MainLayout.razor.css, and #blazor-error-ui already declares color-scheme: light only, so it must stay light by design. wwwroot/app.css sets link and .btn-primary colours in hex and reads --bs-secondary-color for placeholders, which tells the agent the Bootstrap variables are the right seam.

It then reads the render modes, because a toggle has to run somewhere. Program.cs adds AddInteractiveServerComponents() and maps App with AddInteractiveServerRenderMode(), Pages/Home.razor has no render mode and is static server-rendered, Pages/Counter.razor and Pages/MoviePages/Index.razor declare @rendermode InteractiveServer, and Pages/Weather.razor uses [StreamRendering]. The layout is shared by all of them, so a toggle in MainLayout needs its own @rendermode InteractiveServer to handle clicks on a static page. ReconnectModal.razor already shows the pattern of a component that loads its own JavaScript through @Assets, and Program.cs calls MapStaticAssets, so a new script gets the same fingerprinting.

The change sets data-bs-theme on <html> and lets Bootstrap do the rest. A small wwwroot/js/theme.js, loaded in App.razor's head before the stylesheets, reads a theme key from localStorage, falls back to prefers-color-scheme, and sets document.documentElement.dataset.bsTheme before the first paint, following the functions Bootstrap's own color mode docs lay out, so there is no light flash. It also exports a setTheme function and listens for system changes while the stored value is auto. A ThemeToggle.razor component with @rendermode InteractiveServer renders a three-way light, dark and auto control, calls setTheme through IJSRuntime, and sits in the top-row of MainLayout.razor beside the About link. The scoped .top-row colours become var(--bs-tertiary-bg) and var(--bs-border-color), the sidebar gradient keeps its two fixed colours since it is dark in both modes, and app.css keeps its brand hex values while the QuickGrid's table class, the forms on Create.razor and Edit.razor and the Paginator follow Bootstrap's dark variables untouched.

In its sandbox the agent installs the .NET 10 SDK and Docker (sudo apt-get install -y docker.io, then starts dockerd), starts a SQL Server container and points ConnectionStrings__BlazorWebAppMoviesContext at it so SeedData.Initialize can run at startup, then runs dotnet build and dotnet run on the http profile's port 5128. In a browser it screenshots /, /movies and /movies/create in light and dark, toggles on the static home page to show the interactive component works there, reloads to show the choice survives, and records a short capture of a cold load in dark mode to show no flash.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add dark mode to this Blazor Web App. Read Program.cs, Components/App.razor, Components/Routes.razor, Components/Layout/MainLayout.razor and its .razor.css, Components/Layout/NavMenu.razor and its .razor.css, Components/Layout/ReconnectModal.razor, Components/Pages/Home.razor, Components/Pages/Counter.razor, Components/Pages/MoviePages/Index.razor, wwwroot/app.css, the header of wwwroot/lib/bootstrap/dist/css/bootstrap.min.css, appsettings.json and Properties/launchSettings.json first. Use Bootstrap 5.3 color modes: add a small script, loaded in the head before the stylesheets through the Assets helper, that sets data-bs-theme on the html element from localStorage or prefers-color-scheme before first paint and keeps following the system while the choice is auto; add a ThemeToggle component with the interactive server render mode that offers light, dark and auto and calls the script through IJSRuntime; place it in the layout's top row; and replace hardcoded light colours in the scoped layout CSS with Bootstrap variables, leaving the error UI light-only as it already is. Install the .NET SDK and Docker, start a SQL Server container and set the connection string to it so the seed runs, build and run the app, screenshot the home, movies and create pages in both modes, toggle from the static home page, reload to show the choice persists, and capture a cold load in dark mode. Open a pull request with the screenshots and the build output. Do not change the pages' render modes or the movie components.",
  "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

The pull request adds wwwroot/js/theme.js and Components/Layout/ThemeToggle.razor, and changes Components/App.razor, Components/Layout/MainLayout.razor and MainLayout.razor.css. Its description holds six screenshots, the home, movies and create pages in each mode, plus a frame sequence from the cold load in dark mode with no light frame, and the dotnet build output.

A paragraph explains the two moving parts: the script sets data-bs-theme before Bootstrap's CSS applies, so the first paint is already right, and the toggle is an interactive server component so it works on Home, which is otherwise static. It lists the scoped CSS lines that moved to Bootstrap variables and the ones left alone, with the error UI's color-scheme: light only named as deliberate.

Before merging, a reviewer checks the sidebar gradient against the dark palette, decides whether auto should be the default for new visitors or light should stay, and considers whether the preference should also be a cookie so prerendering can emit the attribute server-side for users with JavaScript off.

Run it on every Linear issue labelled theme

In the Project that holds the app, add an automation with this prompt and a linear trigger on linear.issue.labeled filtered to the theme label. Each labelled issue starts one run in its own sandbox and ends in one pull request; the issue's text follows the prompt as data, so an issue that asks for a dark variant of the sidebar gradient or a toggle in the nav menu instead of the top row makes its own change. Changes made by an app integration never fire the trigger, and the automation's max_runs_per_hour caps how many issues become runs at once.

From your own server the same run is one POST /o/{org}/sessions per issue, with the repository in resources and the issue's https://linear.app/<workspace>/issue/<ID> URL there too, so Rush reads it through your Linear connection into the prompt. A webhook_url on the key reports run.completed or run.failed with the session_url when the turn finishes.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A theme is judged on pages, not on a diff, and the moment that matters is the first paint of a cold load. The agent installs the .NET SDK and Docker in its own sandbox, starts the SQL Server the seed needs, and has a browser, so it runs the app the way launchSettings.json does and brings back screenshots and a load capture instead of a promise that the flash is gone.

The decisions are this repository's: Bootstrap 5.3.3 already bundled, a static home page that forces the toggle to be interactive, scoped CSS with hardcoded light colours and an error banner that must stay light. The build log and the images stay with the run, and the same prompt runs against every Blazor app a team maintains, each in its own sandbox.

Frequently asked questions

Why not toggle a CSS class instead of data-bs-theme?

Because the bundled Bootstrap is 5.3.3, whose color modes are keyed on the data-bs-theme attribute and restyle tables, forms, buttons and the navbar from one attribute on <html>. A class would mean rewriting those rules by hand; the attribute means most of the app follows with no CSS change.

Will the page flash light before going dark?

No. theme.js is loaded in the head before the stylesheets and sets the attribute from localStorage or prefers-color-scheme before the first paint; Blazor's own script loads at the end of the body as before. The description includes a frame capture of a cold load to show it.

Does the toggle work on the static Home page?

Yes. Home.razor has no render mode, so a plain button there would not handle clicks; ThemeToggle.razor declares @rendermode InteractiveServer itself, and the layout hosts it on every page. The agent toggles from / in its screenshots for that reason.

What about the reconnect modal and the error banner?

#blazor-error-ui already sets color-scheme: light only and is left that way, so an error stays readable whatever the theme. The reconnect modal has its own scoped CSS; the agent checks it in dark mode and changes it only if a colour is hardcoded there.

More Blazor jobs

The same job on other stacks

Keep reading