Repository navigation
fix(admin): normalize manually-typed slug inputs on blur - #1844
ColoradoClimbr wants to merge 7 commits into
Conversation
🦋 Changeset detectedLatest commit: 12c176a The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
3dec250 to
f4f44ca
Compare
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
f4f44ca to
842fc00
Compare
|
Rebased onto latest main to resolve the ContentSettingsPanel.tsx conflict (main's own Sortable-sections refactor landed after this branch; kept main's structure, carried over just the onBlur wiring). All checks green. Marking ready for review. |
|
This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity. If you're still working on this, please push an update or leave a comment. |
|
Still active — no conflicts, checks green, just waiting on review. |
There was a problem hiding this comment.
This PR fixes a real UX inconsistency: manually-typed slug inputs were stored raw until the server silently normalized them, so the field showed an invalid value between editing and save. Normalizing on blur is the right call (per-keystroke normalization would strip the separator the user just typed), and extracting small named helpers for the snake_case paths keeps auto-generation and blur handling in sync.
I read the full diff, the changed source files, the slugify utility, the affected tests, and AGENTS.md. The implementation is correct, but test coverage is incomplete for a bug fix: only ContentEditor and ContentTypeEditor got regression tests, while FieldEditor, SectionEditor, Sections, TaxonomyManager, and BylineFieldEditor received the same blur-normalization behavior without corresponding tests. I also found one slug-style input in TaxonomyManager (CreateTaxonomyDialog name) that still lacks blur normalization.
Overall: good approach, clean code, but more tests are needed before this bug can be considered fully fixed across every touched site.
Findings
-
[needs fixing]
packages/admin/src/components/FieldEditor.tsx:422This PR adds blur normalization to slug inputs in
ContentEditor,ContentSettingsPanelbyline dialogs,ContentTypeEditor,FieldEditor,SectionEditor,Sections,TaxonomyManager, andBylineFieldEditor, but onlyContentEditorandContentTypeEditorgot regression tests. Existing test files forFieldEditor,SectionEditor,Sections, andTaxonomyManageralready render these dialogs and can assert the normalized value after blur;BylineFieldEditorneeds a new test or coverage through its parent. Per AGENTS.md, "a bug without a reproducing test is not fixed." Add blur-normalization test cases for the remaining components so a regression in any one of them fails CI. -
[suggestion]
packages/admin/src/components/TaxonomyManager.tsx:655TermFormDialog's slug now normalizes on blur, butCreateTaxonomyDialog'snameinput is the same kind of snake_case identifier and is still normalized only when the label auto-generates it. A user can typeMy Taxonomy!into the name field, see the invalid raw value, and get a validation error on submit. Add anonBlurthat reuses the same auto-gen normalization so the behavior is consistent within this component.<Input label={t`Name`} value={name} onChange={(e) => { setName(e.target.value); setAutoName(false); }} onBlur={() => setName((current) => current .toLowerCase() .replace(NON_ALPHANUMERIC_PATTERN, "_") .replace(LEADING_TRAILING_UNDERSCORE_PATTERN, ""), ) } placeholder="genre" required pattern="[a-z][a-z0-9_]*" title={t`Lowercase letters, numbers, and underscores only, starting with a letter`} />
FieldEditor, SectionEditor, Sections, TaxonomyManager, and BylineFieldEditor all got the same onBlur slug normalization as ContentEditor/ContentTypeEditor, but only those two got regression tests. Add the matching case to each: fill the slug manually, blur by moving focus, assert the normalized value.
Visual regression: 22 screens changedThese admin screens render differently on this PR. Confirm every change below is intended before accepting.
Maintainers: if every change above is intended, comment Measured head: |
|
CI is green except Visual Regression, which reports snapshot drift. I don't think this diff changes anything visual (it only adds onBlur handlers), so I'd guess baseline drift from main, but I can't accept baselines from a fork. Could a maintainer take a look and /accept-baselines if the diff looks right? |
|
Thanks so much for sticking with this, @marcusbellamyshaw-cell, and for rebasing it by hand. You're right that the diff doesn't change anything visual: the baselines on main have moved since your run, and admin PRs from current main pass Visual Regression again. I've added A few points from emdashbot's earlier review are still open. Once they're done, this should be close to ready:
Then add |
|
This PR is waiting on its author because it has merge conflicts with |
978d503 to
12c176a
Compare
Query-count snapshot changes45 routes changed, total Δ +9 queries. SQLite
D1
Comparing snapshot files between base and head. Updated automatically on each push. |
There was a problem hiding this comment.
Normalizing on blur is still the right approach: it avoids stripping separators mid-typing and keeps manual entry consistent with auto-generation. The earlier test-coverage gap is addressed, since FieldEditor, SectionEditor, Sections, TaxonomyManager and BylineFieldEditor now have blur tests. Two issues need fixing. First, blurring an empty slug passes it through slugify(), which returns an untitled-* placeholder, so the placeholder gets saved. Second, the changeset claims byline quick-create/edit coverage that the diff does not provide. The earlier suggestion to add blur normalization to the CreateTaxonomyDialog name input is still open and is carried forward below. There is also a minor comment-discipline note. Both reviewers worked statically and did not run tests.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol. The change since the last review (2150 lines) was too large for a scoped follow-up, so this is a full review.
| // word break). Auto-generated slugs (title -> slug above) don't have | ||
| // this problem since the title field is a separate, already-complete input. | ||
| const handleSlugBlur = React.useCallback(() => { | ||
| setSlug((current) => slugify(current)); |
There was a problem hiding this comment.
[needs fixing] slugify() never returns an empty string: for "" or input with no letters or digits it returns a hash-based untitled-xxxxxxx fallback. This handler runs on every blur, so tabbing through or clearing the Slug field now installs a synthetic slug and marks the form dirty.
- Previously an empty slug was sent as
slug || undefined, so creation could derive it from the title and an existing item's slug stayed unchanged. Now the placeholder is sent explicitly by both save and autosave, and it can rename an existing item's URL. - An editor also can't clear a slug anymore.
The same problem applies to the new handlers in SectionEditor.tsx:286, Sections.tsx:190 and TaxonomyManager.tsx:587. Those inputs are required, so the placeholder silently satisfies the check.
Guard the empty case, e.g. setSlug((current) => (current.trim() ? slugify(current) : current));. Apply it at all four sites and add a clear-and-blur regression test.
| "@emdash-cms/admin": patch | ||
| --- | ||
|
|
||
| Normalizes manually-typed slug inputs (content items, taxonomy terms, sections, collections, custom fields, byline quick-create/edit) to their expected format on blur, matching the existing auto-generate-from-label behavior. Previously a manually-typed slug was stored raw (spaces, capitals, punctuation) until the underlying handler silently transformed it, showing a visibly invalid value in a field labeled "URL-friendly identifier." |
There was a problem hiding this comment.
[needs fixing] The changeset (and the PR description) claims byline quick-create/edit dialogs are normalized, but they are not.
- Those dialogs are
BylineProfileDialoginBylineCreditsEditor.tsx, whose "URL slug" input only callsonSlugChangeand stores the raw value. That file isn't touched by this diff. - Typing
My Byline!still shows the raw text and failsvalidateProfileon submit. - The
/bylinesroute slug input (routes/bylines.tsx:491) is also untouched. BylineFieldEditoris the custom-field schema editor, not these dialogs.
Either add blur normalization using toBylineSlug, with create/edit tests, or correct the changeset to name what actually changed.
| // Normalize on blur rather than on every keystroke -- slugify() strips | ||
| // trailing hyphens, so live normalization would eat the separator the | ||
| // user just typed (e.g. "My " -> "my" -> next keystroke appends with no | ||
| // word break). Auto-generated slugs (title -> slug above) don't have | ||
| // this problem since the title field is a separate, already-complete input. |
There was a problem hiding this comment.
[suggestion] This comment explains the rejected alternative ("rather than on every keystroke…") and a hypothetical example, which belongs in the PR description. Reduce it to one line, e.g. // slugify strips trailing hyphens, so normalize on blur, not per keystroke.
The (#1567) issue references in test names (ContentEditor.test.tsx:509, and the section comment in ContentTypeEditor.test.tsx:124) also go stale and should be dropped.






















What does this PR do?
Manual edits to a Slug field were stored raw (spaces, capitals, punctuation) — inconsistent with auto-generated slugs, which already go through
slugify()/an inline snake_case equivalent from the label field. The raw value only got normalized once the save request hit the handler, so the field visibly showed an invalid value between typing and save/reload.Normalizes on blur rather than onChange:
slugify()strips trailing hyphens, so live per-keystroke normalization would eat the word separator the user just typed (e.g. "My " -> "my" -> next keystroke appends with no break). Blur avoids that while still guaranteeing the stored value is always valid once the user moves on.Covers all 7 manual slug inputs found: ContentEditor's main slug field and both byline quick-create/edit dialogs (kebab-case via the shared
slugify()), TaxonomyManager, SectionEditor, Sections (create dialog) (also kebab-case), and ContentTypeEditor + FieldEditor + BylineFieldEditor (snake_case, collection/field slugs use/^[a-z][a-z0-9_]*$/perschema/registry.ts— extracted each file's existing inline regex chain into a small named helper reused by both the auto-gen and new blur paths, rather than duplicating it a second time in the same file).Closes #1567
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure
Screenshots / test output
packages/admin/tests/components/ContentEditor.test.tsx+ContentTypeEditor.test.tsx— 85/85 pass, covering both slug conventions;pnpm lint:quickclean;pnpm typecheckclean.Opened as draft: fork already has several open PRs against this repo (non-collaborator open-PR limit).