WordPress.org

Make WordPress Core

Opened 7 weeks ago

Closed 37 hours ago

Last modified 16 hours ago

#47216 closed defect (bug) (fixed)

Block Editor crashes on custom post types without title support

Reported by: markjaquith Owned by:
Milestone: 5.3 Priority: high
Severity: normal Version:
Component: Editor Keywords: has-patch
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 6 days ago.
Patches cleanForSlug to not fail when the parameter isn't a string.
47216.2.patch (461 bytes) - added by splitti 6 days ago.
Updated patch that follows the coding standards

Download all attachments as: .zip

Change History (10)

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


6 weeks ago

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


5 weeks ago

#3 @desrosj
5 weeks ago

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

#4 @splitti
6 days 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
6 days 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.


6 days ago

@splitti
6 days ago

Updated patch that follows the coding standards

#6 @splitti
6 days ago

Adjusted the patch to follow the coding standards :)

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


43 hours ago

#8 @SergeyBiryukov
37 hours 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 16 hours ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.