Skip to content
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

Edit Post: "View Post" link doesn't change when publishing draft #15402

Closed
aduth opened this issue May 2, 2019 · 1 comment
Closed

Edit Post: "View Post" link doesn't change when publishing draft #15402

aduth opened this issue May 2, 2019 · 1 comment
Labels
[Feature] Saving Related to saving functionality Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Package] Edit Post /packages/edit-post [Type] Bug An existing feature does not function as intended

Comments

@aduth
Copy link
Member

aduth commented May 2, 2019

Previously: #14740 (comment)

When editing an existing post, a "View Post" link appears in the admin toolbar.

image

This link is intended to be automatically updated when the link for the post changes (e.g. changing the permalink and updating a published post):

// Update View Post link in the admin bar when permalink is updated.
yield __unstableSubscribe( ( registry ) => onChangeListener(
() => registry.select( 'core/editor' ).getCurrentPost().link,
( newPermalink ) => {
if ( ! newPermalink ) {
return;
}
const nodeToUpdate = document.querySelector( VIEW_AS_LINK_SELECTOR );
if ( ! nodeToUpdate ) {
return;
}
nodeToUpdate.setAttribute( 'href', newPermalink );
}
) );

However, the above implementation relies on a selector which is effective only for published posts, not for drafts:

export const VIEW_AS_LINK_SELECTOR = '#wp-admin-bar-view a';

The link for a draft uses a different ID wp-admin-bar-preview.

Steps to Reproduce:

  1. Navigate to Posts > Add New
  2. Enter a title
  3. Click "Save Draft"
  4. Reload
  5. (Optional) Take note of the link for "View Post"
  6. Publish the post
  7. Note that the link for "View Post" does not change (still links to preview by draft ID)

Needs More Information:

The links in the admin bar are dynamically generated. It's not entirely clear to follow which possible selector values must be accounted for.

https://github.com/WordPress/wordpress-develop/blob/5640763da953c28033e9f285c7c2a1da4c613aa3/src/wp-includes/class-wp-admin-bar.php#L464

@aduth aduth added [Type] Bug An existing feature does not function as intended Good First Issue An issue that's suitable for someone looking to contribute for the first time [Feature] Saving Related to saving functionality [Package] Edit Post /packages/edit-post labels May 2, 2019
@gziolo gziolo added the Needs Dev Ready for, and needs developer efforts label Oct 21, 2019
@obenland
Copy link
Member

I followed the testing instructions and was unable to reproduce the bug.
#15444 adds an additional selector there VIEW_AS_PREVIEW_LINK_SELECTOR, which fixed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Saving Related to saving functionality Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Package] Edit Post /packages/edit-post [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants