Skip to main content

Tell the CSS scanner what it may read

30 October 2026 · AI-built UI · the engineering team

The story

Our stylesheet imported Tailwind with automatic detection. That mode scans the root of the Vite project, which here is the whole repository, minus whatever .gitignore excludes. So it read more than the app. Text in the docs and in the tests counted as source, and classes found there went into the shipped CSS.

We found 21 such classes. Three of them were bg-blue-500, text-slate-700 and border-red-200. No page uses them, and the fingerprint does not see them either.

The fix was to stop scanning by default. The stylesheet now imports Tailwind with its automatic source switched off, and names two sources: our own source directory and the built output of our component package. The inline token safelist for the public site is unchanged. We also added a guard test. It requires every named source path to sit under the fingerprint's paths or under the component package's built output.

The pattern

A scanner that finds its own inputs will find more than you meant. Automatic detection is a reasonable default, but it makes the input set a property of the repository's contents, and the repository holds more than code. Docs and tests are full of class-like words, and the scanner has no way to tell an example from a use.

So name the sources. A stylesheet that lists what it may read has an input set you can read in one place. Then check the list. Our guard test asserts that the stylesheet imports Tailwind with the automatic scan off, and that no other stylesheet imports Tailwind. It also asserts that every named source path lies under the fingerprint's paths or the component package's output. Anything outside both fails the test with the stylesheet and the path in the message.

The same idea applies to anything an agent or a tool picks up by walking a directory. If the walk decides what ships, the walk needs a list.

Try it

Find where your CSS tool decides what to scan. If the answer is "the project root", do three things.

  1. Switch off automatic detection and list each source you want read, by path.

  2. Compare the built CSS before and after. Any class that disappears came from somewhere you did not name, so check whether a page needed it.

  3. Add a test that fails when a source path falls outside the directories your build already tracks, and when a second stylesheet imports the tool without the same setting.

tailwindcssbuildtesting