Opened 8 weeks ago
Last modified 7 weeks ago
#61751 accepted defect (bug)
Custom post type editor working
Reported by: | karan4word | Owned by: | TimothyBlynJacobs |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 6.6.1 |
Component: | Editor | Keywords: | has-patch |
Focuses: | javascript, administration, rest-api | Cc: |
Description (last modified by )
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)
Change History (14)
#3
@
8 weeks 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
@
8 weeks 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
@
8 weeks 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
@
8 weeks ago
I found two similar lines, but I do not know whether the issue is only in private-selectors
.
editor.js
(store/private-selectors) minifies ton?.icon?.startsWith("dashicons-")
edit-site.js
(add-new-template/utils) outputsicon:e.icon?.startsWith("dashicons-")
#7
@
8 weeks ago
The block editor makes assumptions about icon
values based on the REST API schema, which states that they can be string' or
null`.
@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.
#8
@
8 weeks 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
@
7 weeks 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
@
7 weeks ago
@karan4word, do you mind commenting on the Gutenberg PR so I can give you the contribution props?
#11
@
7 weeks ago
@Mamaduka Done here https://github.com/WordPress/gutenberg/pull/64015#issuecomment-2261491127
Showing this error to editors and admin