seatonjiang / kratos

WordPress theme that focus on reading experience
GNU General Public License v3.0
3.13k stars 613 forks source link

新建侧边栏小工具报错 #521

Closed barryblueice closed 1 year ago

barryblueice commented 2 years ago

TypeError: Cannot read properties of undefined (reading 'get') at Ne._createWidget (https://c0.wp.com/c/6.0.1/wp-includes/js/dist/customize-widgets.min.js:7:30146) at https://c0.wp.com/c/6.0.1/wp-includes/js/dist/customize-widgets.min.js:7:31231 at Array.map () at Ne._updateWidgets (https://c0.wp.com/c/6.0.1/wp-includes/js/dist/customize-widgets.min.js:7:31137) at Ne.setWidgets (https://c0.wp.com/c/6.0.1/wp-includes/js/dist/customize-widgets.min.js:7:31426) at https://c0.wp.com/c/6.0.1/wp-includes/js/dist/customize-widgets.min.js:7:17182 at pt (https://c0.wp.com/c/6.0.1/wp-includes/js/dist/vendor/react-dom.min.js:9:44204) at ht (https://c0.wp.com/c/6.0.1/wp-includes/js/dist/vendor/react-dom.min.js:9:44658) at Object.useState (https://c0.wp.com/c/6.0.1/wp-includes/js/dist/vendor/react-dom.min.js:9:107007) at e.useState (https://c0.wp.com/c/6.0.1/wp-includes/js/dist/vendor/react.min.js:9:10899) 切成其他主题就没有报错……

barryblueice commented 2 years ago

已经找到原因了,打开Gutenberg 编辑器就会报错,关闭就不会报错。

n0099 commented 2 years ago

可以复现

在启用gutenberg时使用新版的采用区块编辑器的/wp-admin/widgets.php随便插入一个区块(不是legacy widgets里的,其是禁用gutenberg时在widgets.php添加的那种旧版小工具)并保存就会导致

There was an error. Cannot read properties of undefined (reading 'hasOwnProperty')

image /wp-includes/js/dist/edit-widgets.min.jsimage

image 本质上是因为/wp-json/batch/v1的后端返回了http400 The provided widget type (id_base) cannot be updated.错误 image

这个错误来自 https://core.trac.wordpress.org/browser/tags/6.0.2/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php#L552

n0099 commented 2 years ago

罪魁祸首找到了:https://github.com/seatonjiang/kratos/blob/dc88428c960dcfa77fc7ad7ef0fb59203e0732a4/inc/theme-widgets.php#L37-L56 https://developer.wordpress.org/reference/classes/wp_widget_block/

seatonjiang commented 1 year ago

这个问题已经修复了,由于在经典模式禁用了WP_Widget_Block,所以在古登堡模式会出异常,更新主题版本即可修复。

image