Slug Generation: fix silent no-op and stale applied state for edited slugs - #932
Conversation
…slugs Hand-edited slugs are normalized with cleanForSlug() on apply, which caused two problems in both the modal and the pre-publish panel: 1. Input that normalizes to an empty slug (for example "!!!") was silently dropped. The modal still closed as if the slug had been applied, with no feedback anywhere. 2. The pre-publish panel compared the raw input against the stored slug, so after applying an edited value like "My Cool Slug" the button stayed on an enabled "Apply" forever and the "Applied" state was unreachable. Fix both at the source. applySlug() now returns the slug it applied, or an empty string when nothing was applied. A shared helper describes how the input will be applied, so both surfaces show the same help text under the field: a preview of the normalized form when it differs, and an explanation when the input cannot become a slug, with Apply disabled in that case. The applied state is now derived from the normalized form, and the modal only closes when something was actually applied. Percent-encoded slugs (how non-Latin suggestions are stored after sanitize_title()) are excluded from the preview, since cleanForSlug() does not account for octets and the preview would advertise a garbled form for a suggestion the user never edited. This is documented as a limitation along with the underlying behaviour.
Add three tests to the slug generation spec: 1. Input that cannot become a slug blocks Apply with an explanation, and even a forced click leaves the modal open and the post slug untouched. 2. An edited slug shows the normalized preview and applies the normalized form from the modal. 3. The pre-publish panel blocks unusable input the same way, flips Apply to a disabled Applied after applying an edited slug, and the normalized form is what lands on the post. Locators for the panel are scoped to the panel container so other sidebar buttons cannot make them ambiguous.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #932 +/- ##
==========================================
Coverage 75.95% 75.95%
Complexity 2989 2989
==========================================
Files 124 124
Lines 11850 11850
==========================================
Hits 9001 9001
Misses 2849 2849
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… in all scenarios
|
Note that E2E tests aren't running right know due to WordPress 7.0.4 not being properly tagged on GitHub:
I've run those locally and they are all passing so going to merge this in |
Description
The Slug Generation experiment lets users hand-edit a suggested slug before applying it, in both the permalink modal and the pre-publish panel. Edits are normalized with
cleanForSlug()on apply, and two problems came out of that:!!!) was silently dropped. The modal still closed as if the slug had been applied, with no feedback anywhere, and the panel button did nothing on click.My Cool Slugthe post correctly receivedmy-cool-slug, but the button stayed on an enabled Apply forever and the Applied state was unreachable.Before
Modal, input that cannot become a slug, Apply closes the modal with nothing applied and no feedback:
Panel, edited slug is applied but the button never reflects it:
After
Modal stays open with the Apply button disabled and an explanation:
Panel previews the normalized form and flips to a disabled Applied:
How it is fixed
Everything rides on existing core pieces.
applySlug()now returns the slug it applied, or an empty string when nothing was applied. A small shared helper describes how the current input will be applied, and both surfaces use it the same way:helpprop ofTextControl) previews the normalized form when it differs from the input, for exampleWill be applied as "my-cool-slug".Percent-encoded slugs (how non-Latin suggestions are stored after
sanitize_title()) are excluded from the preview, sincecleanForSlug()does not account for octets and the preview would show a garbled form for a suggestion the user never edited. The underlying apply behaviour for those slugs is pre-existing and is now noted in the doc's Limitations section.Testing
npm run lint:jsand the TypeScript check pass. No PHP changes.The docs page is updated to match, including the Manual Testing steps and a Limitations entry.
Use of AI Tools
This PR was developed with the assistance of AI tools for local testing, code review and drafting, with all changes reviewed and verified by me.
Changelog Entry