Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ function ( $block ) {
array(
'blockTypes' => array_values( $block_types ),
'postType' => get_post_type(),
'StrictMode' => true,
Copy link
Copy Markdown
Contributor

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, the setState gate is this.subscribed || acf.get('StrictMode') — so setting this to true means setState is always called regardless of subscribed state, even on WP < 6.9 where React StrictMode is not active.

Would it make sense to gate this on WP 6.9+? Something like:

'StrictMode' => version_compare( $GLOBALS['wp_version'], '6.9', '>=' ),

That way the behavior on older WP versions stays unchanged, and we only opt into the StrictMode path where React actually uses it.

)
);

Expand Down Expand Up @@ -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();
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix follows the existing pattern for $block and $raw_context above — nice.

Could you add a PHPUnit test for this? Something like a test in tests/phpunit/ that calls acf_ajax_fetch_block() (or the relevant helper) with query as a JSON string and verifies it gets decoded to an array without error. The $block and $raw_context decoding paths above would also benefit from tests eventually, but covering this new path would be a good start.


// Bail early if no block.
if ( ! $block ) {
wp_send_json_error();
Expand Down
Loading