Make WordPress Core

Opened 15 months ago

Last modified 3 months ago

#59915 new defect (bug)

Preview Whilst Editing Broken

Reported by: simonjonharding's profile simonjonharding Owned by:
Milestone: Priority: normal
Severity: minor Version: 6.4.2
Component: Editor Keywords: reporter-feedback
Focuses: ui, javascript Cc:

Description

When editing a page or post, trying to preview using the top right icon results in the URL
wp-admin/undefined

Previewing from the list of posts or pages works OK

Change History (11)

#1 @jorbin
15 months ago

  • Component changed from General to Editor
  • Keywords reporter-feedback added
  • Milestone Awaiting Review deleted

Hi @simonjonharding, welcome to trac and thanks for reporting this issue.

I'm not able to replicate this on 6.4.1 or with trunk. I tested with both published posts and drafts.

Can you confirm that you are seeing this issue with the default twentytwentyfour theme and no plugins activated? If this is still an issue, I think it will be best to report it in the Gutenberg repo as that is where the UI for the editor is developed.

#3 @jorbin
14 months ago

@jgutix

Are you able to replicate this on one of the default themes without any plugins? If not, can you provide sample code or instructions to replicate since this is not reproducible on a clean install.

#4 @mcsr
12 months ago

  • Version changed from 6.4 to 6.4.2

I'm experiencing the same issue. My WordPress site is running on WordPress 6.4.2.

When manually opening the preview link in a new tab, the preview works fine. But when just clicking on the preview button in the Gutenberg editor, the browser is getting redirected to /wp-admin/undefined. I'm experiencing this on the default post types (pages, posts) as well as custom post types.

With previous versions of WP this worked fine. We didn't change anything to the theme or plugins, so I can't imagine what's causing this issue.

#5 @jorbin
12 months ago

@mcsr are you able to replicate this issue on one of the default themes without any plugins? If not, can you provide sample code or instructions to replicate since this is not reproducible on a clean install.

#6 @mcsr
12 months ago

@jorbin We could bring the issue down to single plugin that caused the issue. After disabling the plugin and/or a fix from the plugin's developers, everything worked fine again.
Thanks!

#7 @jgutix
12 months ago

@mcsr which plugin is that?

#8 @jgutix
12 months ago

  • Focuses ui javascript added

The plugin that seems to be affecting is Yoast SEO, I disabled it and was able to use the preview link, here is the report in their github: https://github.com/Yoast/wordpress-seo/issues/21133

#9 @simonjonharding
12 months ago

I originally posted the issue, but the problem seems to have resolved in my installation.
However I dont use Yoast SEO. I have not been able to determine whether the issue has been cleared from a wordpress update or a plugin update.

#10 @mcsr
12 months ago

@jgutix Interesting. We're also using Yoast Free, but didn't have any issues with it. In our case, it was caused by PublishPress Checklists

#11 @jgutix
3 months ago

Turns out it was our legacy code at fault for the issue in our installation, we had something like this:

  var editor = wp.data.dispatch( 'core/editor' );
  ....

  // Reference original method.
  var savePost = editor.savePost;
  .....

  // Override core method.
  editor.savePost = function() {
    var currentPost = wp.data.select('core/editor').getCurrentPost();
    var postPublished = wp.data.select( 'core/editor' ).isCurrentPostPublished();
    var postStatus = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'status' ); 

    if ((postStatus == 'draft') || (!postPublished && postStatus == 'auto-draft')) {

      notices.removeNotice('excerptNotice');
      notices.removeNotice('postCategoryNotice');
      excerptNotice = null;
      postCategoryNotice = null;
      savePost();

      return false;
    }
    ....

We were returning false which then returned the preview link as undefined

It was simply fixed by changing the last two lines to: return savePost();

P.S.: At this point I'm not sure why disabling Yoast allowed the post to be previewed ¯\_(ツ)_/¯

Note: See TracTickets for help on using tickets.