Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bug Fixes

- Error boundary: Explicitly announce the error title and description, excluding action labels ([#82737](https://github.com/WordPress/gutenberg/pull/82737)).
- `PostURL`: Leaving the slug field without typing no longer saves the displayed fallback as the slug, so a new post no longer publishes with the `auto-draft` slug ([#83518](https://github.com/WordPress/gutenberg/pull/83518)).

## 15.1.0 (2026-09-23)

Expand Down
17 changes: 12 additions & 5 deletions packages/editor/src/components/post-url/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function PostURL( { onClose } ) {
const {
isEditable,
postSlug,
hasSlug,
postLink,
permalinkPrefix,
permalinkSuffix,
Expand All @@ -51,6 +52,7 @@ export default function PostURL( { onClose } ) {
postSlug: safeDecodeURIComponent(
select( editorStore ).getEditedPostSlug()
),
hasSlug: !! select( editorStore ).getEditedPostAttribute( 'slug' ),
viewPostLabel: postType?.labels?.view_item,
postLink: post.link,
permalinkPrefix: permalinkParts?.prefix,
Expand Down Expand Up @@ -141,11 +143,16 @@ export default function PostURL( { onClose } ) {
}
} }
onBlur={ ( event ) => {
editPost( {
slug: cleanForSlug(
event.target.value
),
} );
// Without a slug the field shows a fallback, which for
// a new post is the `auto-draft` placeholder. Writing
// it would pin that value as the post slug.
if ( hasSlug ) {
editPost( {
slug: cleanForSlug(
event.target.value
),
} );
}
if ( forceEmptyField ) {
setForceEmptyField( false );
}
Expand Down
25 changes: 25 additions & 0 deletions test/e2e/specs/editor/various/sidebar-permalink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test.describe( 'Sidebar Permalink', () => {
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllPosts();
await requestUtils.deactivatePlugin(
'gutenberg-test-custom-post-types'
);
Expand Down Expand Up @@ -75,4 +76,28 @@ test.describe( 'Sidebar Permalink', () => {
page.getByRole( 'button', { name: 'Change link' } )
).toBeVisible();
} );

test( 'should not save the placeholder slug of a new post when the slug field loses focus', async ( {
admin,
editor,
page,
requestUtils,
} ) => {
await admin.createNewPost();
await editor.openDocumentSettingsSidebar();
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'Hello Slug' );

await page.getByRole( 'button', { name: /^Change link/ } ).click();
await page.getByRole( 'textbox', { name: 'Slug' } ).click();
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Escape' );

const postId = await editor.publishPost();
const post = await requestUtils.rest( {
path: `/wp/v2/posts/${ postId }`,
} );
expect( post.slug ).toBe( 'hello-slug' );
} );
} );
Loading