Make WordPress Core

Opened 2 years ago

Closed 19 months ago

#61751 closed defect (bug) (fixed)

Custom post type editor not working

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

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 2 years ago.
Showing this error to editors and admin

Download all attachments as: .zip

Change History (24)

@karan4word
2 years ago

Showing this error to editors and admin

#1 @karan4word
2 years ago

Showing error only on editing any custom post type

#2 @sabernhardt
2 years ago

  • Description modified (diff)

#3 @Mamaduka
2 years 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
2 years 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
2 years 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
2 years ago

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

#7 @Mamaduka
2 years 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.

Last edited 2 years ago by Mamaduka (previous) (diff)

#8 @Mamaduka
2 years 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
2 years ago

  • Focuses rest-api added
  • Severity blocker → 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
2 years 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
2 years 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
2 years ago

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

Yeah I think so.

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


2 years ago

#15 @chaion07
2 years ago

  • Milestone 6.7 → 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!

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


20 months ago

#17 @joedolson
20 months ago

  • Summary Custom post type editor working → Custom post type editor not working

#18 @jorbin
20 months ago

... until we decide whether to fix register_post_type or the REST API?

por que no los dos? I think the solution here should be:

1) Force the correct shape in the REST API

and

2) Emit a doing_it_wrong when you call register_post_type with incorrect types.

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


19 months ago

#20 @audrasjb
19 months ago

Given the main issue was fixed on Gutenberg side, should we close this as fixed and open a new ticket for further changes? Pinging @TimothyBlynJacobs @jorbin.

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


19 months ago

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


19 months ago

#23 @audrasjb
19 months ago

  • Resolution → fixed
  • Status accepted → closed

As per today's bug scrub: Closing this as fixed in milestone 6.8. Further changes can happen in new follow-up tickets.

Note: See TracTickets for help on using tickets.