Hello GreenShift team,
we found a reproducible editor crash in the Border control (GreenShift 13.2.0, WordPress 7.1.2, also affects the Container block and any block using the border attribute).
Summary
When a block’s border attribute contains empty arrays instead of empty objects, e.g.
“border”:{“borderRadius”:{“values”:[],”locked”:true},”style”:{“all”:[“solid”]},”size”:{“all”:[1]},”color”:{“all”:[“#e6e6e6″]},”styleHover”:[],”sizeHover”:[],”colorHover”:[],”custom”:[],”customEnabled”:[]}
the first change in the Border panel silently deletes borderRadius.values, and the next interaction with the radius crashes the block (“This block has encountered an error and cannot be previewed”).
Why the data contains [] instead of {}
Any server-side round trip through PHP (parse_blocks() / json_decode(…, true) followed by serialize_blocks() / json_encode()) turns an empty object {} into an empty array [], because PHP cannot distinguish the two. This happens routinely with WPML (translation jobs re-serialize block attributes), with migrations and with programmatic content updates. On our site 103 posts / 1,615 attribute values were affected, mostly WPML translations.
Root cause in build/gspbLibrary.js (Border control)
- clear_null_values() (minified as Qm) deletes properties where the check
null != e[t] && 0 != e[t]fails. For an empty object0 != {}is true, but for an empty array0 != []is false ([] coerces to “” and then to 0). So all empty arrays are deleted, including borderRadius.values. - The radius handler then reads
o?.borderRadius?.values[e](4 occurrences). The optional chain does not protect the bracket access, so whenvaluesis undefined this throwsTypeError: Cannot read properties of undefined (reading 'topLeft').
Steps to reproduce
- Insert a Container block and save a post whose content contains the border attribute above (with “values”:[]).
- Open the post in the editor, select the block, change any border setting (e.g. width or color).
- Change the border radius -> the block crashes.
Suggested fix
- Use
o?.borderRadius?.values?.[e]in the radius handler, and/or - normalise the border attribute on load (convert [] to {} for values, style, size, color, styleHover, sizeHover, colorHover, custom, customEnabled), and/or
- in clear_null_values(), do not rely on
0 != value; check explicitly for null/undefined/”” and treat empty arrays like empty objects.
As a workaround we converted the affected attributes in the database from [] to {}, but they will reappear with the next WPML translation sync, so a fix in the plugin would be much appreciated.
Thank you and best regards
Manfred
cobizz GmbH, Wuppertal
Responses