WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 days ago

#47216 reopened defect (bug)

Block Editor crashes on custom post types without title support

Reported by: markjaquith Owned by:
Milestone: 5.2.3 Priority: high
Severity: normal Version:
Component: Editor Keywords: has-patch needs-testing fixed-major
Focuses: javascript Cc:

Description

Create a custom post type that supports 'editor' but not 'title'. Save Draft. Reload the page. Crashes.

<?php
add_action( 'init', function () {
        register_post_type( 'movie',
                [
                        'labels' => [
                                        'name' => 'Movies',
                                        'singular_name' => 'Movie',
                        ],
                        'public' => true,
                        'has_archive' => true,
                        'rewrite' => [
                                'slug' => 'movies'
                        ],
                        'show_in_rest' => true,
                        'supports' => [
                                //'title',
                                'editor',
                        ],
                ]
        );
});

Attachments (2)

47216.1.patch (452 bytes) - added by splitti 2 months ago.
Patches cleanForSlug to not fail when the parameter isn't a string.
47216.2.patch (461 bytes) - added by splitti 2 months ago.
Updated patch that follows the coding standards

Download all attachments as: .zip

Change History (11)

This ticket was mentioned in Slack in #core-editor by earnjam. View the logs.


3 months ago

This ticket was mentioned in Slack in #core by desrosj. View the logs.


3 months ago

#3 @desrosj
3 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.3
  • Priority changed from normal to high

#4 @splitti
2 months ago

  • Keywords has-patch added; needs-patch removed

The problem is caused by this line in PostLink.

It assumes that cleanForSlug (see here) can deal with parameters that aren't strings. If this were a documentary, the narrator would now say "It can't."

There are at least two options on how to resolve this problem.

  1. Make cleanForSlug bail whenever it gets invalid input.
  2. Change the code in PostLink (and potentially elsewhere) to not call cleanForSlug with something that isn't always a string.

Following the Robustness Principle, I opted for (1) in my patch.
I'm not sure what's the best way to indicate that the function wasn't able to perform the desired action, but I think returning undefined is probably a good start, but I'd like to hear your opinions on that as well as any preference for another option :)

@splitti
2 months ago

Patches cleanForSlug to not fail when the parameter isn't a string.

This ticket was mentioned in Slack in #core-js by splitti. View the logs.


2 months ago

@splitti
2 months ago

Updated patch that follows the coding standards

#6 @splitti
2 months ago

Adjusted the patch to follow the coding standards :)

This ticket was mentioned in Slack in #core-editor by chrisvanpatten. View the logs.


8 weeks ago

#8 @SergeyBiryukov
8 weeks ago

  • Resolution set to fixed
  • Status changed from new to closed

The patch has been merged in https://github.com/WordPress/gutenberg/pull/16236 and should be included in core the next time Gutenberg packages are merged.

Last edited 8 weeks ago by SergeyBiryukov (previous) (diff)

#9 @JeffPaul
3 days ago

  • Keywords needs-testing fixed-major added
  • Milestone changed from 5.3 to 5.2.3
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening this so it can be back-ported to the 5.2 branch, also needs testing to validate if this ticket is good to land in 5.2.3.

Note: See TracTickets for help on using tickets.