Repository navigation
fix(blocks): reset local meta after preview render - #526
faisalahammad wants to merge 1 commit into
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. |
|
Thanks for the contribution and the effort here! 🙏 A heads-up on how this repo works: a large part of SCF's codebase (field types, Flexible Content, Blocks v3, local fields, forms, value formatting, and most of includes/ and assets/src/js/) is regularly synced from an upstream codebase. Any change we make there, whether a bug fix or a new feature, gets overwritten or causes hard merge conflicts on the next sync. That includes features behind a beta flag. Fixes for those areas arrive through the sync itself, so we can't accept PRs that touch that code, even good ones. |
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.