-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server side render encodes some attributes incorrectly #7086
Comments
Additional additional context: this is happening when passing attributes with array values to the |
Whoa I've been tearing my hair out all day trying to get this to work! Thought it was just me. Would it be possible to change the call to the server change to a POST? |
I've been working through this for a while and found that @miina was registering the attributes in the
After adding this in my php file (and also making sure the attributes were in the block's js file) booleans worked fine. I haven't tried an array @timothyjensen but hopefully this helps you make some progress! |
@brianpiccione I think normal types, like |
Gotcha, thanks Chris. It'd be good to add this requirement (registering the atts in PHP) to the docs. I went down a number of rabbit holes to find this! Let me know if I can help at all |
One idea for this would be to use a JS equivalent of PHP's http_build_query, which is capable of transforming complex arrays/objects into a query string. |
* Improve serialising JSON to PHP-compatible query strings (fixes #7086) * Fix an eslint issue (unused `map` method) * Update http-build-query to 0.7.0 * ServerSideRender: remove an over-scoped function and a default value for attributes * ServerSideRender: cleanup unused var (oups, linting..) * ServerSideRender: tests for `http-build-query` * allow null default for attributes
I'm running into a situation where my attributes are being returned in an unexpected format. For example, an array of Post IDs is converted to an array that contains one comma separated string.
Expected:
Observed:
Another example is an array of objects is converted to
[object Object],[object Object]
. Both cases are problematic because the data are inconsistent between the post editor and front end. Having to account for both formats increases the chances of buggy code.I have narrowed the problem down to
getQueryUrlFromObject
, though I can't offer a solution.gutenberg/components/server-side-render/index.js
Lines 68 to 74 in 7066905
Additional context
The text was updated successfully, but these errors were encountered: