Skip to content

fix(admin): normalize manually-typed slug inputs on blur - #1844

Closed
ColoradoClimbr wants to merge 7 commits into
emdash-cms:mainfrom
Emdash-Bug-Testing:fix/1567-admin-slug-normalize-on-blur
Closed

ColoradoClimbr wants to merge 7 commits into
emdash-cms:mainfrom
Emdash-Bug-Testing:fix/1567-admin-slug-normalize-on-blur

Conversation

@ColoradoClimbr

Copy link
Copy Markdown
Contributor

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_]*$/ per schema/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

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (n/a — no new user-visible strings)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion (n/a — bug fix)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Sonnet 5

Screenshots / test output

packages/admin/tests/components/ContentEditor.test.tsx + ContentTypeEditor.test.tsx — 85/85 pass, covering both slug conventions; pnpm lint:quick clean; pnpm typecheck clean.

Opened as draft: fork already has several open PRs against this repo (non-collaborator open-PR limit).

@changeset-bot

changeset-bot Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 12c176a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1844

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1844

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@1844

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1844

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1844

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@1844

emdash

npm i https://pkg.pr.new/emdash@1844

create-emdash

npm i https://pkg.pr.new/create-emdash@1844

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1844

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@1844

@emdash-cms/plugin-test

npm i https://pkg.pr.new/@emdash-cms/plugin-test@1844

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@1844

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@1844

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@1844

@emdash-cms/registry-loader

npm i https://pkg.pr.new/@emdash-cms/registry-loader@1844

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@1844

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@1844

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@1844

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1844

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1844

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1844

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1844

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1844

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1844

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@1844

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1844

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1844

commit: 978d503

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@ColoradoClimbr
ColoradoClimbr force-pushed the fix/1567-admin-slug-normalize-on-blur branch from f4f44ca to 842fc00 Compare July 24, 2026 04:36
@ColoradoClimbr

Copy link
Copy Markdown
Contributor Author

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.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the stale label Aug 7, 2026
@ColoradoClimbr

Copy link
Copy Markdown
Contributor Author

Still active — no conflicts, checks green, just waiting on review.

@github-actions github-actions Bot removed the stale label Aug 7, 2026
@ColoradoClimbr
ColoradoClimbr marked this pull request as ready for review August 12, 2026 07:41
@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Aug 12, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:422

    This PR adds blur normalization to slug inputs in ContentEditor, ContentSettingsPanel byline dialogs, ContentTypeEditor, FieldEditor, SectionEditor, Sections, TaxonomyManager, and BylineFieldEditor, but only ContentEditor and ContentTypeEditor got regression tests. Existing test files for FieldEditor, SectionEditor, Sections, and TaxonomyManager already render these dialogs and can assert the normalized value after blur; BylineFieldEditor needs 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:655

    TermFormDialog's slug now normalizes on blur, but CreateTaxonomyDialog's name input is the same kind of snake_case identifier and is still normalized only when the label auto-generates it. A user can type My Taxonomy! into the name field, see the invalid raw value, and get a validation error on submit. Add an onBlur that 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`}
    						/>
    

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Aug 12, 2026
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.
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Aug 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Visual regression: 22 screens changed

These admin screens render differently on this PR. Confirm every change below is intended before accepting.

Screen Image Compare
content-editor-ltr expected · actual
content-editor-rtl expected · actual
content-list-byline-filter-ltr expected · actual
content-list-byline-filter-rtl expected · actual
content-list-date-field-filter-ltr expected · actual
content-list-date-field-filter-rtl expected · actual
content-list-date-range-filter-ltr expected · actual
content-list-date-range-filter-rtl expected · actual
content-list-ltr expected · actual
content-list-rtl expected · actual
content-list-status-filter-ltr expected · actual
content-list-status-filter-rtl expected · actual
content-new-ltr expected · actual
content-new-rtl expected · actual
dashboard-ltr expected · actual
dashboard-rtl expected · actual
media-ltr expected · actual
media-rtl expected · actual
menus-ltr expected · actual
menus-rtl expected · actual
settings-ltr expected · actual
settings-rtl expected · actual

Maintainers: if every change above is intended, comment /accept-baselines
to commit the regenerated Linux baselines to this PR.

Measured head: 978d5032896563c5a65c22f9347e3e46b4e80584. /accept-baselines accepts the snapshots for this commit.

@ColoradoClimbr

Copy link
Copy Markdown
Contributor Author

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?

@swissky

swissky commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

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 ci:run so it runs fresh.

A few points from emdashbot's earlier review are still open. Once they're done, this should be close to ready:

  • A regression test for the remaining slug inputs (FieldEditor, SectionEditor, Sections, TaxonomyManager, BylineFieldEditor). A blur test like the two you already wrote is enough for each.
  • The name field in CreateTaxonomyDialog still needs the same blur normalization.
  • Please drop the (#1567) from the test name. The bot flags issue references in new code and test names.

Then add bot:review (or ping here) and we'll take another look.

@swissky swissky added the ci:run Approve and re-run CI on the PR's latest commit label Oct 4, 2026
@github-actions github-actions Bot removed the ci:run Approve and re-run CI on the PR's latest commit label Oct 4, 2026
github-actions Bot pushed a commit that referenced this pull request Oct 4, 2026
@github-actions github-actions Bot added needs-rebase review/needs-review No maintainer or bot review yet and removed review/needs-rereview New commits since the last review labels Oct 6, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR is waiting on its author because it has merge conflicts with main, and it has had no activity for 14 days. It will be closed in 7 days unless there is activity: push an update or leave a comment to keep it open.

@github-actions github-actions Bot added stale and removed stale labels Oct 19, 2026
@ColoradoClimbr
ColoradoClimbr force-pushed the fix/1567-admin-slug-normalize-on-blur branch from 978d503 to 12c176a Compare October 23, 2026 23:23
@github-actions github-actions Bot added the query-count changed PR diff modifies query-count snapshot files label Oct 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Query-count snapshot changes

45 routes changed, total Δ +9 queries.

SQLite

Route Before After Δ
GET / (cold) 5 6 +1
GET / (warm) 5 6 +1
GET /category/development (cold) 10 12 +2
GET /category/development (warm) 9 11 +2
GET /contributors (cold) 5 6 +1
GET /contributors (warm) 5 6 +1
GET /contributors-naive (cold) 12 13 +1
GET /contributors-naive (warm) 12 13 +1
GET /pages/about (cold) 4 6 +2
GET /pages/about (warm) 4 6 +2
GET /posts (cold) 5 6 +1
GET /posts (warm) 5 6 +1
GET /posts/building-for-the-long-term (cold) 14 17 +3
GET /posts/building-for-the-long-term (warm) 13 17 +4
GET /related (cold) 8 — removed
GET /related (warm) 8 — removed
GET /related-baseline (cold) 5 — removed
GET /related-baseline (warm) 5 — removed
GET /search (cold) 5 11 +6
GET /search (warm) 5 11 +6
GET /tag/webdev (cold) 9 11 +2
GET /tag/webdev (warm) 9 11 +2

D1

Route Before After Δ
GET / (cold) 22 17 -5
GET / (warm) 5 6 +1
GET /category/development (cold) 21 23 +2
GET /category/development (warm) 9 11 +2
GET /contributors (cold) 15 17 +2
GET /contributors (warm) 5 6 +1
GET /contributors-naive (cold) 22 24 +2
GET /contributors-naive (warm) 12 13 +1
GET /pages/about (cold) 13 17 +4
GET /pages/about (warm) 4 6 +2
GET /posts (cold) 15 17 +2
GET /posts (warm) 5 6 +1
GET /posts/building-for-the-long-term (cold) 24 28 +4
GET /posts/building-for-the-long-term (warm) 13 17 +4
GET /related (cold) 18 — removed
GET /related (warm) 8 — removed
GET /related-baseline (cold) 15 — removed
GET /related-baseline (warm) 5 — removed
GET /rss.xml (cold) 11 12 +1
GET /search (cold) 14 22 +8
GET /search (warm) 5 11 +6
GET /tag/webdev (cold) 21 23 +2
GET /tag/webdev (warm) 9 11 +2

Comparing snapshot files between base and head. Updated automatically on each push.

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The changeset (and the PR description) claims byline quick-create/edit dialogs are normalized, but they are not.

  • Those dialogs are BylineProfileDialog in BylineCreditsEditor.tsx, whose "URL slug" input only calls onSlugChange and stores the raw value. That file isn't touched by this diff.
  • Typing My Byline! still shows the raw text and fails validateProfile on submit.
  • The /bylines route slug input (routes/bylines.tsx:491) is also untouched.
  • BylineFieldEditor is 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.

Comment on lines +601 to +605
// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@Emdash-Bug-Testing Emdash-Bug-Testing closed this by deleting the head repository Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/admin cla: signed needs-rebase query-count changed PR diff modifies query-count snapshot files review/needs-review No maintainer or bot review yet size/M stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin slug inputs should normalize to kebab-case on change

3 participants