Make WordPress Core

Opened 6 months ago

Last modified 3 months ago

#61751 accepted defect (bug)

Custom post type editor working

Reported by: karan4word's profile karan4word Owned by: timothyblynjacobs's profile TimothyBlynJacobs
Milestone: 6.8 Priority: normal
Severity: normal Version: 6.6.1
Component: Editor Keywords: has-patch
Focuses: javascript, administration, rest-api Cc:

Description (last modified by sabernhardt)

After updating to the latest WordPress version 6.6.1
Its gives error :

 TypeError: n?.icon?.startsWith is not a function
    at https://domainname.gov.uk/wp-includes/js/dist/editor.min.js?ver=8607251058f984a77c8f:7:56973
    at r (https://domainname.gov.uk/wp-includes/js/dist/data.min.js?ver=7c62e39de0308c73d50c:2:9528)
    at Proxy.r (https://domainname.gov.uk/wp-includes/js/dist/data.min.js?ver=7c62e39de0308c73d50c:2:16845)
    at https://domainname.gov.uk/wp-includes/js/dist/editor.min.js?ver=8607251058f984a77c8f:7:79624
    at https://domainname.gov.uk/wp-includes/js/dist/data.min.js?ver=7c62e39de0308c73d50c:9:2045
    at __unstableMarkListeningStores (https://domainname.gov.uk/wp-includes/js/dist/data.min.js?ver=7c62e39de0308c73d50c:2:22094)
    at Object.__unstableMarkListeningStores (https://domainname.gov.uk/wp-includes/js/dist/data.min.js?ver=7c62e39de0308c73d50c:2:22352)
    at p (https://domainname.gov.uk/wp-includes/js/dist/data.min.js?ver=7c62e39de0308c73d50c:9:2010)
    at https://domainname.gov.uk/wp-includes/js/dist/data.min.js?ver=7c62e39de0308c73d50c:9:2612
    at Qe (https://domainname.gov.uk/wp-includes/js/dist/data.min.js?ver=7c62e39de0308c73d50c:9:2824)

To fix it we have rolled back to WordPress 5.5 version.

Attachments (1)

error.JPG (31.4 KB) - added by karan4word 6 months ago.
Showing this error to editors and admin

Download all attachments as: .zip

Change History (16)

@karan4word
6 months ago

Showing this error to editors and admin

#1 @karan4word
6 months ago

Showing error only on editing any custom post type

#2 @sabernhardt
6 months ago

  • Description modified (diff)

#3 @Mamaduka
6 months ago

The error is probably coming from this line - https://github.com/WordPress/gutenberg/blob/3336ee9bc3490dee6d6d843a8a83229df33bfccd/packages/editor/src/store/private-selectors.js#L113.

@karan4word, it looks like your custom post types defines menu_icon property that isn't string.

Can you run following code in DevTools console, when error occurs and share the returned object?

wp.data.select( 'core' ).getPostType( wp.data.select( 'core/editor' ).getCurrentPostType() );

#4 @karan4word
6 months ago

The error also comes while creating any new post with any custom post type

That js code returns this object on dev tools console

{
    "capabilities": {
        "edit_post": "edit_post",
        "read_post": "read_post",
        "delete_post": "delete_post",
        "edit_posts": "edit_posts",
        "edit_others_posts": "edit_others_posts",
        "delete_posts": "delete_posts",
        "publish_posts": "publish_posts",
        "read_private_posts": "read_private_posts",
        "read": "read",
        "delete_private_posts": "delete_private_posts",
        "delete_published_posts": "delete_published_posts",
        "delete_others_posts": "delete_others_posts",
        "edit_private_posts": "edit_private_posts",
        "edit_published_posts": "edit_published_posts",
        "create_posts": "edit_posts"
    },
    "description": "",
    "hierarchical": false,
    "has_archive": false,
    "visibility": {
        "show_in_nav_menus": true,
        "show_ui": true
    },
    "viewable": true,
    "labels": {
        "name": "Stories",
        "singular_name": "Story",
        "add_new": "Add New",
        "add_new_item": "Add New Story",
        "edit_item": "Edit Story",
        "new_item": "New Story",
        "view_item": "View Story",
        "view_items": "View Posts",
        "search_items": "Search Stories",
        "not_found": "No Stories found",
        "not_found_in_trash": "No Stories found in Trash",
        "parent_item_colon": null,
        "all_items": "Stories",
        "archives": "Stories",
        "attributes": "Post Attributes",
        "insert_into_item": "Insert into post",
        "uploaded_to_this_item": "Uploaded to this post",
        "featured_image": "Featured image",
        "set_featured_image": "Set featured image",
        "remove_featured_image": "Remove featured image",
        "use_featured_image": "Use as featured image",
        "filter_items_list": "Filter posts list",
        "filter_by_date": "Filter by date",
        "items_list_navigation": "Posts list navigation",
        "items_list": "Posts list",
        "item_published": "Post published.",
        "item_published_privately": "Post published privately.",
        "item_reverted_to_draft": "Post reverted to draft.",
        "item_trashed": "Post binned.",
        "item_scheduled": "Post scheduled.",
        "item_updated": "Post updated.",
        "item_link": "Post Link",
        "item_link_description": "A link to a post.",
        "menu_name": "Stories",
        "name_admin_bar": "Story",
        "template_name": "Single item: Story"
    },
    "name": "Stories",
    "slug": "story",
    "icon": false,
    "supports": {
        "title": true,
        "editor": true,
        "excerpt": true,
        "custom-fields": true,
        "thumbnail": true,
        "author": true,
        "page-attributes": true,
        "autosave": true
    },
    "taxonomies": [
        "category",
        "post_tag"
    ],
    "rest_base": "story",
    "rest_namespace": "wp/v2",
    "template": [],
    "template_lock": false,
    "yoast_head": null,
    "yoast_head_json": null,
    "_links": {
        "collection": [
            {
                "href": "https://domainname.gov.uk/wp-json/wp/v2/types"
            }
        ],
        "wp:items": [
            {
                "href": "https://domainname.gov.uk/wp-json/wp/v2/story"
            }
        ],
        "curies": [
            {
                "name": "wp",
                "href": "https://api.w.org/{rel}",
                "templated": true
            }
        ]
    }
}

#5 @karan4word
6 months ago

After Setting up icon with custom post type it's allowing to edit and create posts under that custom post type but it should work fine without setting up any icon as well.

#6 @sabernhardt
6 months ago

I found two similar lines, but I do not know whether the issue is only in private-selectors.

#7 @Mamaduka
6 months ago

The block editor makes assumptions about icon values based on the REST API schema, which states that they can be string' or null`.

See https://github.com/WordPress/wordpress-develop/blob/c41304d73c32c968056abd2b1ffa19e83e9833a9/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php#L412-L417.

@karan4word, it looks like you're setting the menu_icon property to false, which causes the error.

I'll update the code to avoid errors when the icon doesn't match the schema type.

Version 0, edited 6 months ago by Mamaduka (next)

#8 @Mamaduka
6 months ago

  • Keywords has-patch added; needs-testing removed

Here's my proposed fix - https://github.com/WordPress/gutenberg/pull/64015.

Should we also harden the checks in REST API to ensure they always return the types specified in the schema?

cc @spacedmonkey, @TimothyBlynJacobs

#9 @TimothyBlynJacobs
6 months ago

  • Focuses rest-api added
  • Severity changed from blocker to normal

Here's my proposed fix - https://github.com/WordPress/gutenberg/pull/64015.

It seems reasonable to me that GB expect that the REST API returns values of the type it documents. I imagine there are other parts of GB that would break if the REST API started returning data in unexpected shapes. So personally I'm not 100% sure on the need to change GB but :shrug:

Should we also harden the checks in REST API to ensure they always return the types specified in the schema?

I think we should probably fix this in register_post_type to coerce the value to string|null since it doesn't document false as a possible property value for menu_icon.

#10 @Mamaduka
6 months ago

@karan4word, do you mind commenting on the Gutenberg PR so I can give you the contribution props?

PR: https://github.com/WordPress/gutenberg/pull/64015

#12 @Mamaduka
6 months ago

The bug has been fixed upstream. It will be included in the next minor release.

@sabernhardt, @TimothyBlynJacobs, should we keep this ticket open until we decide whether to fix register_post_type or the REST API?

#13 @TimothyBlynJacobs
6 months ago

  • Milestone changed from Awaiting Review to 6.7
  • Owner set to TimothyBlynJacobs
  • Status changed from new to accepted

Yeah I think so.

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


3 months ago

#15 @chaion07
3 months ago

  • Milestone changed from 6.7 to 6.8

Thanks @karan4word for reporting this. As we move closer to the RC1 for 6.7 in a matter of days and with no progress in this cycle, we are updating the milestone following the feedback received from a recent bug-scrub session.

Cheers!

Note: See TracTickets for help on using tickets.