-
Notifications
You must be signed in to change notification settings - Fork 53
Fix block editor rendering: query decoding and StrictMode #391
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -914,6 +914,7 @@ function ( $block ) { | |
| array( | ||
| 'blockTypes' => array_values( $block_types ), | ||
| 'postType' => get_post_type(), | ||
| 'StrictMode' => true, | ||
| ) | ||
| ); | ||
|
|
||
|
|
@@ -1031,6 +1032,16 @@ function acf_ajax_fetch_block() { | |
| $raw_context = $args['context']; | ||
| $post_id = $args['post_id']; | ||
|
|
||
| // Decode query if sent as a JSON string instead of an array. | ||
| // The block editor JS may serialize the query parameter as JSON, | ||
| // which causes a fatal TypeError on PHP 8.4 when accessing offsets. | ||
| if ( is_string( $query ) ) { | ||
| $query = json_decode( wp_unslash( $query ), true ); | ||
| if ( ! is_array( $query ) ) { | ||
| $query = array(); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fix follows the existing pattern for Could you add a PHPUnit test for this? Something like a test in |
||
|
|
||
| // Bail early if no block. | ||
| if ( ! $block ) { | ||
| wp_send_json_error(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enables the StrictMode code path on all WP versions. In
acf-pro-blocks.js, thesetStategate isthis.subscribed || acf.get('StrictMode')— so setting this totruemeanssetStateis always called regardless ofsubscribedstate, even on WP < 6.9 where React StrictMode is not active.Would it make sense to gate this on WP 6.9+? Something like:
That way the behavior on older WP versions stays unchanged, and we only opt into the StrictMode path where React actually uses it.