Fix block editor rendering: query decoding and StrictMode#391
Open
adrianmomorales wants to merge 2 commits intoWordPress:trunkfrom
Open
Fix block editor rendering: query decoding and StrictMode#391adrianmomorales wants to merge 2 commits intoWordPress:trunkfrom
adrianmomorales wants to merge 2 commits intoWordPress:trunkfrom
Conversation
Two fixes for block rendering in the Gutenberg editor:
1. Decode $query when sent as JSON string in acf_ajax_fetch_block().
The block editor JS may serialize the query parameter as a JSON string,
but the PHP code assumes it is already an array. On PHP 8.4 this causes
a fatal TypeError: "Cannot access offset of type string on string".
2. Enable StrictMode flag in localized block editor data.
The block JS already has code to handle React 18 StrictMode
(mount → unmount → remount), gated behind acf.get('StrictMode'),
but the flag was never set. Without it, blocks inserted in the editor
show an infinite spinner because setState is skipped when the component
is remounted after StrictMode cleanup.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @adrianmomorales. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two fixes for ACF block rendering in the Gutenberg editor:
1. Decode
$querywhen sent as JSON string (acf_ajax_fetch_block)The block editor JS may serialize the
queryparameter as a JSON string, butacf_ajax_fetch_block()assumes it is already a PHP array. On PHP 8.4 this causes a fatal TypeError at line 1099:The
$blockand$contextparameters are already decoded withjson_decode()(lines 1040-1046), but$queryis not. This adds the same treatment.2. Enable
StrictModeflag in localized block editor dataThe block editor JS already has code to handle React 18 StrictMode (mount → unmount → remount), gated behind
acf.get('StrictMode'):But the flag is never set —
acf.get('StrictMode')always returnsnull. Without it, when React StrictMode remounts a block component,this.subscribedisfalse(set during unmount) andsuper.setState()is skipped. The block form HTML is fetched successfully but never rendered — the block shows an infinite spinner.This adds
'StrictMode' => trueto the localized data inacf_enqueue_block_assets().Steps to reproduce
acf_block_version: 2andmode: editTest plan
🤖 Generated with Claude Code