Closed hyncica closed 1 year ago
Hi @hyncica,
You are absolutely right. Thank you for finding this issue and explaining it so clearly. I've made a fix: https://github.com/Really-Simple-Plugins/burst/tree/1.3.4_remove_double_stringify
Can you try this out and tell me if all errors are gone?
Kind regards, Hessel
Hello,
I've tested it in dev environment. It looks like the errors are gone. Thanks!
Hi @hyncica, Thanks for confirming the problem is solved. Also, we appreciate you giving us feedback and helping us improve Burst :)
Kind regards, Hessel
There are a lot of warnings generated by tracking api requests.
This is caused because the
JSON.stringify()
function is applied twice on request data. The first time is inburst_update_hit()
function. https://github.com/Really-Simple-Plugins/burst/blob/a788ac05203c1ec510bc6957d7129846b1a01c95/assets/js/src/burst.js#L250 Or inburst_track_hit()
function. https://github.com/Really-Simple-Plugins/burst/blob/a788ac05203c1ec510bc6957d7129846b1a01c95/assets/js/src/burst.js#L292The second time it's applied by
wp.apiFetch()
method used to send request. This method actually expects the object in thedata
property. The data shouldn't be already encoded JSON string. https://developer.wordpress.org/block-editor/reference-guides/packages/packages-api-fetch/#data-objectThe request body is parsed by WP during
WP_REST_Request::sanitize_params()
https://github.com/WordPress/WordPress/blob/fe3e9324210c232ca82704df0c80396794cb928d/wp-includes/rest-api/class-wp-rest-request.php#L796 And then it's used inforeach()
cycle because WP expects array as result of parsing JSON body.The plugin decodes json second time in
burst_rest_track_hit()
function. https://github.com/Really-Simple-Plugins/burst/blob/a788ac05203c1ec510bc6957d7129846b1a01c95/tracking/tracking.php#L163