DEV Community

Sherotree
Sherotree

Posted on Fully Autonomous

Give the agent the existing color-mode hook, not a local darkMode boolean

The PR adds a theme toggle with a local darkMode boolean, a document.documentElement.classList.toggle("dark"), and maybe a raw localStorage key. The repo already has a useColorMode (or useTheme) hook that owns the document class, the system preference, and persistence. Nearby header and settings rows use it. The local boolean flashes on first paint, fights the existing class name, and stores a second key.

I've started treating a local darkMode boolean as a second theme, not as a quicker toggle. Flipping a class is the easy part. A shared mode, a first-paint contract, and one persistence path are why the hook is there.

Why the local boolean shows up

A tutorial "dark mode" example is a useState flag and a classList toggle. The model can write that without finding useColorMode or the existing theme provider. Your hook may be named useTheme, useColorScheme, or live on the design-system provider, which is easy to miss if the prompt only says "add a dark mode toggle."

You also skip the system preference, the first-paint script, and the rule about not inventing a second theme context for one settings row.

A simple color-mode policy

  • New theme toggles use the existing color-mode hook or provider
  • Do not keep a local darkMode boolean in a feature file
  • Do not toggle the document class or a storage key ad hoc
  • A new mode or persistence rule is a hook or provider change, with a test

If the job is a single surface that is always dark, that is a local tone token, not a product-wide mode. If storage already goes through the existing wrapper, do not add a raw localStorage key for theme.

What to put in the prompt

Use the existing color-mode hook for this theme toggle.
Do not keep a local darkMode boolean, and do not toggle the document class in this file.
Keep system preference, first paint, and persistence on the shared hook or provider.
If only one surface is inverted, use a local tone token instead of a product-wide mode.
Enter fullscreen mode Exit fullscreen mode

Paste one existing hook usage. In review, search the diff for a darkMode or isDark state, a classList.toggle("dark"), and a new theme storage key.

Reject / send back

Reject

  • A feature-level theme toggle that reimplements the color-mode hook
  • A local darkMode boolean that writes the document class itself
  • A second theme key in storage when the hook already persists the mode
  • A second theme provider added for one settings row

Accept

  • A toggle that uses the existing color-mode hook or provider
  • A hook PR that adds a documented mode or persistence case and a test
  • A single-surface tone that never claimed to be the product color mode

Top comments (0)