-
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
[2.9] permalink should be reassigned to new title after clearing URL #7002
Comments
Is this a regression or has this always been the case? (I feel like other editors for WordPress exhibit similar behaviours but I can't recall.) |
After testing this out a bit at least part of the issue is the new slug for the new title isn't immediately available to the |
It looks like, because the permalink is created by the API, we have to wait until the content is updated. I'm new to the project and don't have a clear idea of where that happens yet but this seems to cause the permalink not to appear immediately editable too. This diff will change an empty slug to the new one when a title changes, but it requires something else is typed and the page is autosaved to update first: --- a/editor/components/post-permalink/editor.js
+++ b/editor/components/post-permalink/editor.js
@@ -23,13 +23,13 @@ class PostPermalinkEditor extends Component {
}
onSavePermalink( event ) {
- const postName = this.state.editedPostName.replace( /\s+/g, '-' );
+ const postName = this.state.editedPostName.length ?
+ this.state.editedPostName.replace( /\s+/g, '-' ) :
+ this.props.permalinkParts.generatedSlug;
event.preventDefault();
- this.props.onSave();
-
- if ( postName === this.props.postName ) {
+ if ( postName === this.props.permalinkParts.postName ) {
return;
}
@@ -40,6 +40,8 @@ class PostPermalinkEditor extends Component {
this.setState( {
editedPostName: postName,
} );
+
+ this.props.onSave();
}
render() {
diff --git a/editor/store/selectors.js b/editor/store/selectors.js
index 4f192a358b35..4fc8ee953717 100644
--- a/editor/store/selectors.js
+++ b/editor/store/selectors.js
@@ -1664,6 +1664,7 @@ export function getPermalinkParts( state ) {
const [ prefix, suffix ] = permalinkTemplate.split( PERMALINK_POSTNAME_REGEX );
return {
+ generatedSlug: getEditedPostAttribute( state, 'generated_slug' ),
prefix,
postName,
suffix, |
This persists through 3.1.1. |
I can confirm this issue is still present in version 3.9.0 however when you update or publish the page (in my case I cloned a page so it had the old URL in, changed the page name, deleted the old permalink and clicked OK, the old permalink remained) the new permalink is used. So the issue is that it doesn't show it straight away when clearing the URL field, but it does work so to speak. |
Tested and confirmed using WordPress 4.9.8 and Gutenberg 4.2.0 that emptying the permalink field and saving it after making a title change isn't picked up until the post is explicitly re0saved. (29s)
Result: I expected the permalink to update to the current title but it reverts to the original title but then does get updated to the new one after the post is explicitly saved
|
So this is because In the old editor, this was handled via a call to To fix this properly, we either need to make some new endpoint for getting this value, or we need to recreate I think an interim solution is just to do the same thing to the title that we do to the slug when you edit it now. Basically it's just a partial sanitization to replace spaces with hyphens. See: https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/post-permalink/editor.js#L22 |
Describe the bug
Gutenberg is to reassign a new URL after the title has changed and the URL has been cleared. However, it is not displaying the reassigned URL until after a save.
To Reproduce
Steps to reproduce the behavior:
(caveat: AFTER SAVING, the correct new URL will be reassigned)
Expected behavior
The permalink should be reassigned to the new title after clearing the URL.
The text was updated successfully, but these errors were encountered: