-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor: Optimize the 'PostSlug' component #60422
Conversation
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. |
Size Change: -128 B (0%) Total Size: 1.73 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @Mamaduka! 🚀
This is a really cool improvement and I see a few positive improvements to the UX 🌟 :
- Slug is currently being kept up to date with the one in the store. We still allow custom non-saved slug to be kept in the meantime. ✅
- Non-slug characters are cleaned up earlier (on change), instead of staying there in the field forever. ✅
- Clearing the field and blurring it will reset to the current slug, which reflects the current state better than before. ✅
One thing that could be improved in the future (not for this PR):
- If we use an existing slug that's already taken by another post, we'll get no indication that this is happening. Once we save, and refresh, we'll see our slug (say
hello-world
) but suffixed by-2
:hello-world-2
, which is the default mechanism of WordPress to deal with duplicate slugs. That's fine, of course, but ideally we should get an indication that it's happening earlier than after refreshing the page.
Side note: I was surprised this used a different component than what Pages are using for managing their slug:
spellCheck="false" | ||
value={ forceEmptyField ? '' : postSlug } | ||
onChange={ ( newValue ) => { | ||
editPost( { slug: newValue } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PostURL
component maintains the same logic. I'm guessing this is to avoid validation while the user is typing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Plus it's definitely not a good user experience if you start typing special characters from an empty field.
export default function PostSlug() { | ||
return ( | ||
<PostSlugCheck> | ||
<PostSlugControl /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call to separate the functionality in a subcomponent so we wouldn't have extra unnecessary store subscriptions when the slug is disabled 👏
Thanks for testing and review, @tyxla! Right, the duplicated post suffix can be "surprise." Validating for it can be expensive, requiring pinging the server. I'm sure there's some old issue, or PR is explaining the decision behind the current logic 😄 |
Co-authored-by: Mamaduka <[email protected]> Co-authored-by: tyxla <[email protected]>
What?
PR contains the following updates and optimizations for the
PostSlug
component:Note
We have to maintain this component for backward compatibility.
Why?
While
core/editor
isn't as active a store ascore/block-editor
, there's no need to create unnecessary store subscriptions.Testing Instructions
add_post_type_support( 'post', 'slug' );
Testing Instructions for Keyboard
Same.
Screenshots or screencast
CleanShot.2024-04-03.at.16.37.48.mp4