research/renaming-an-astro-content-enum-value
Renaming an Enum Value in an Astro Content Collection: What the Build Catches and What It Doesn't
Engineering Note · November 11, 2026 · 7 minute read · Astro · TypeScript · Content Collections
Renaming an enum value in an Astro content collection means changing it in four places: the schema, the content files, any CSS that styles by the value, and any code that filters by it. Astro’s build catches only the second one, and only one file at a time. On Astro 7.3.8 a stale CSS selector, a stale .default() and a stale filter all built without an error, and one post silently disappeared from an index page. A project-wide search for the old string, run before and after, caught all of it.
Everything below was run with Node.js 22.23.4, Astro 7.3.8, zod 4.6.5 (the version Astro installed), @astrojs/check 0.9.12, TypeScript 6.0.3, and Playwright 1.63.0 with Chromium 153 for one style check. We ran it on a throwaway copy of this site’s repository. None of these renames shipped.
What does an enum value touch?
An enum in a content schema is a fixed list of allowed strings. Our Workbench collection has one for project status:
status: z.enum(['Live', 'Custom Solution', 'Beta', 'Research', 'In Development', 'Concept']),
Before changing anything, we searched for the value we planned to rename. This is the real output on our main branch:
grep -rn "In Development" src --include=*.ts --include=*.astro --include=*.css --include=*.md --include=*.mjs | grep -v "^src/content/research/"
src/content/workbench/postracer.md:5:status: In Development
src/content/workbench/prospect-studio.md:5:status: In Development
src/content/workbench/mailtobot.md:5:status: In Development
src/styles/global.css:699:.status[data-s='In Development'] { --dot: var(--orange); }
src/content.config.ts:14: status: z.enum(['Live', 'Custom Solution', 'Beta', 'Research', 'In Development', 'Concept']),
Five places. The CSS line is the one that is easy to forget: the status pill renders data-s={project.data.status}, and the stylesheet colors the dot by matching that attribute. We excluded research posts from the search because this article, and others like it, mention the value in prose.
What happens if you only change the schema?
We changed 'In Development' to 'Building' in content.config.ts and nothing else, then ran npx astro build. It failed in about four seconds:
[InvalidContentEntryDataError] workbench → mailtobot data does not match collection schema.
status: Invalid option: expected one of "Live"|"Custom Solution"|"Beta"|"Research"|"Building"|"Concept"
That is a good error. It names the file, the field and the allowed values. But it names only one file. We fixed mailtobot.md and built again:
[InvalidContentEntryDataError] workbench → postracer data does not match collection schema.
Three affected files took three builds to find. On a larger collection the search is much faster than iterating on the build.
What happens if you forget the CSS?
With all three content files updated, the build passed: exit code 0, 212 pages. The stylesheet still had .status[data-s='In Development'], which now matched nothing.
The dot’s color comes from a custom property with a fallback:
.status::before {
background: var(--dot, var(--gray));
}
So nothing looked broken. It just turned gray, the same gray as the Concept status. We served the built dist folder and read the computed style on one of the renamed pages with Playwright:
await p.$eval('.status', (el) => ({
status: el.dataset.s,
dot: getComputedStyle(el).getPropertyValue('--dot').trim(),
before: getComputedStyle(el, '::before').backgroundColor,
}));
{"status":"Building","dot":"","before":"rgb(125, 133, 144)"}
After changing the selector to data-s='Building' and rebuilding:
{"status":"Building","dot":"#ff5e1f","before":"rgb(255, 94, 31)"}
#7d8590 is our gray token and #ff5e1f our orange. A build cannot know that a selector is meant to match content, so this class of mistake only shows up by searching or by looking.
What about a default value?
Our research collection has a second enum, with a default:
section: z.enum(['Featured Research', 'Engineering Notes']).default('Engineering Notes'),
Thirty-five of our research posts have no section line and rely on that default. One older post sets section: "Engineering Notes" explicitly.
We renamed 'Engineering Notes' to 'Notes' in the list but left the default alone. The first build failed on the one explicit post, which is expected. We updated that post to "Notes" and built again. It passed.
That is the surprise. The default, 'Engineering Notes', is no longer one of the allowed values, and the build accepted it. The 35 posts without a section line received the old string at runtime. In our test, zod 4.6.5 did not validate the default against the enum.
What did that do to the pages?
The research index filters by section in src/pages/research.astro:
const featured = all.filter((p) => p.data.section === 'Featured Research').sort(byDateDesc);
const engineering = all.filter((p) => p.data.section === 'Engineering Notes').sort(byDateDesc);
The stale default and the stale filter agreed with each other, so the 35 defaulted posts still appeared under Engineering Notes. The one post we had correctly renamed to "Notes" matched neither filter. We counted unique /research/ links in the built research.html:
| Build | Unique research links on the index | Renamed post listed? |
|---|---|---|
| Unmodified copy | 57 | Yes |
| Enum renamed, one post updated, default left stale | 56 | No |
The post’s own page was still built at dist/research/claude-code-quota-burn-telemetry.html. It simply dropped off the list. An internal link checker would not catch that, because nothing links to a missing page. A page-count comparison would not catch it either. A comparison of index links does.
Would a type check have caught it?
Partly, and only with the right setup. Our project has no tsconfig.json. With @astrojs/check and TypeScript installed, npx astro check on the unmodified copy reported:
Result (69 files):
- 332 errors
- 0 warnings
Most of these were implicit any types in .astro files, and the same count appeared after our renames. The stale comparison in research.astro was not among them, because the posts come through a helper whose parameters the checker treated as any.
So we tried the narrow version. We added a strict tsconfig.json that included only Astro’s generated types, the content config and a small probe file:
{ "extends": "astro/tsconfigs/strict", "include": [".astro/types.d.ts", "src/lib/enum-probe.ts", "src/content.config.ts"] }
// src/lib/enum-probe.ts
import { getCollection } from 'astro:content';
const all = await getCollection('research');
export const notes = all.filter((p) => p.data.section === 'Engineering Notes');
The check then reported both problems (the second message is trimmed to its first and last lines):
src/lib/enum-probe.ts:4:40 - error ts(2367): This comparison appears to be unintentional because the types '"Featured Research" | "Notes"' and '"Engineering Notes"' have no overlap.
src/content.config.ts:53:61 - error ts(2769): No overload matches this call.
...
Argument of type '"Engineering Notes"' is not assignable to parameter of type '"Featured Research" | "Notes"'.
The same run also printed warning ts(6385): 'z' is deprecated. for the z imported from astro:content, a separate cleanup for later.
The type checker knows the enum. It can only help where your filters are typed, which in our project they mostly are not yet.
A rename checklist
This is the order we will use next time:
- Search the whole project for the old string, excluding prose you do not want to change. Keep the output.
- Change the schema list and any
.default()together. - Change every content file from the search.
- Change every selector and every comparison from the search. Consider exporting the enum values as constants so code imports them instead of repeating strings.
- Search again. The only hits left should be ones you meant to keep.
- Run a strict type check on the files that filter content.
- Build, then compare page counts and index link counts with the last good build.
Steps 1 and 5 caught every mistake in this test. Steps 6 and 7 are the safety net for the next mistake we have not thought of.
Limitations
- We tested one version of each tool, listed at the top. Zod’s handling of defaults, and Astro’s error reporting, may differ in other versions.
- The “one file per build” behavior is what we observed with two collections and up to three bad entries. We did not test whether Astro ever reports several entries at once.
- Our
astro checkresult depends on this project having notsconfig.json. A project that already uses a strict config would see the stale filter in its normal check. - We did not test enum values used in client-side scripts, URLs or query strings. A search finds those too; a build will not.
Related reading
- Typed Content Collections in Astro for a Research Section
- An Internal Link Checker for a Static Build in 34 Lines of Node.js
- Structuring an Astro Static Site with Cloudflare Pages Functions
Frequently asked questions
What happens if I rename an enum value in an Astro schema but not in my content?
The build fails with InvalidContentEntryDataError and names the first entry that does not match. On Astro 7.3.8 it named only one file per run, so with three affected files we needed three builds to find them all. Searching for the old value first is faster.
Does Astro check that a z.enum default is one of the allowed values?
Not at build time in our test. With zod 4.6.5, a schema of z.enum(['Featured Research', 'Notes']).default('Engineering Notes') built without error, and entries with no value received the old string. A strict TypeScript check of the config file did report it, as error ts(2769).
Will astro check catch a filter that compares against a renamed enum value?
It can. With a strict tsconfig, a comparison against the old value in a typed .ts file produced error ts(2367), saying the types have no overlap. In our project, which has no tsconfig.json, astro check reported 332 unrelated errors before and after the rename and did not flag the stale filter.
What is the safest order for renaming a content enum value?
Search for the old string across the whole project first. Then change the schema, the default, the content files, the CSS and the code in one commit, search again to confirm the old string is gone, run a type check and a build, and compare the number of pages and index links with the previous build.