fix(blocks): reset local meta after preview render - #526
Open
faisalahammad wants to merge 1 commit into
Open
Conversation
The preview paths of acf_rendered_block() and acf_rendered_block_v3() call acf_setup_meta() for post-render validation without a matching acf_reset_meta(). While local meta is active for a post id, ACF_Local_Meta::pre_load_metadata() returns null for any meta name not in the local set, so unrelated get_field() calls for the same post id silently return null after a block preview render. - Wrap the three preview acf_setup_meta() call sites in try/finally with acf_reset_meta(), matching the existing pair in the inner acf_render_block() helper - Remove the tear_down workaround in the block render tests that tracked leaked block ids and reset them manually - Add a regression test asserting unrelated post meta survives all three preview render paths Fixes WordPress#455
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
The preview paths of
acf_rendered_block()andacf_rendered_block_v3()callacf_setup_meta()for post-render validation without a matchingacf_reset_meta(). While local meta is active for a post id,ACF_Local_Meta::pre_load_metadata()(includes/local-meta.php:194-203) returns null for any meta name not present in the local set, so unrelatedget_field()calls for the same post id silently return null after a block preview render.This affects three sites in
includes/blocks.php:acf_rendered_block(), the$formbranch (preview edit form)acf_rendered_block(), the preloaded preview re-setup after the inner render callacf_rendered_block_v3(), the unconditional setup used by v3 block previewsFix wraps each
acf_setup_meta()in atry/finallyblock withacf_reset_meta( $block['id'] ), matching the existing pair inside the inneracf_render_block()helper. The regression testtest_rendered_block_does_not_leak_metainserts a post with a known DB value, exercises all three preview paths, and assertsget_post_meta()still returns the DB value. The PHPUnit workaround that tracked leaked block ids and reset them manually intear_downis removed fromtests/php/includes/blocks/test-blocks-render.phpandtests/php/includes/blocks/test-blocks-auto-inline-editing.phpsince the fix prevents the leak.Closes #455
Use of AI Tools
This pull request was prepared with assistance from Claude Code. The change was implemented, tested, and reviewed by hand before submission; the AI was used to find the relevant code paths and run the verification steps outlined in the issue.