Block Render Caching Defeats the Point of Render
- This topic has 4 replies, 2 voices, and was last updated 1 day, 19 hours ago by
Richard Coy.
-
AuthorPosts
-
May 8, 2026 at 11:49 PM #49956
Richard Coy
ParticipantThis update has caused some major issues for us:
- Cache and debounce block preview rendering to improve performanceOur blocks are dynamic, that's the point of the render file. But now they aren't dynamic because of the cache. We are using the post id (among other things) in the render file to display dynamic data. I understand the potential benefits of the cache, but there absolutely should be a setting or at least a filter to avoid the cache. Currently, there's no mechanism to avoid the cache that I could find, so we've had to revert your plugin.
Maybe we're missing something and there's a method already to allow for dynamic blocks using the render attribute? We want to continue using block.json with the WP provided render value, but we don't see how that's possible with your blocks currently.
I also can't find any information about the cache in the docs which is also frustrating.
P.S. Also frustrating that older versions of the plugin are not provided in the account. I had to revert back to an older version rather than the lowest relevant version. Again, maybe I'm missing where to find that?
May 9, 2026 at 5:06 AM #49957Richard Coy
ParticipantTo fully describe the issue, the same meta box blocks are producing the same code on different posts that should be displaying different information.
This is due to a recent update in version 3.6.0 where a block that has the same exact json data is cached improperly. The code in question is in /meta-box-aio/vendor/meta-box/mb-blocks/src/Loader.php:101 in the function
prepare_render_callback_data.The problem is if you copy/paste, duplicate or use a block in a pattern, the json data is identical, but the resulting content should be different based on different factors, like the post loaded, or a user is logged in vs not, etc.
Currently, if you view one post and then another post with an identical block, the second post is displaying the content of the first post.
This doesn't happen if you add the block manually since a random id is added at that time, but if you reuse a block in any way (again, copy/paste, duplicate, pattern), the cache conflicts and a bad cache (incorrect post) is returned.
Recommended solutions:
1. Remove the cache as it defeats the point of render in the first place and goes against what core is doing. Rely on page cache to save resources rather than implementing a custom object cache.
2. Allow an override setting, so that the cache is optional dependent on how the block works. Some could be cached in this manner and work correctly, others can't.To replicate create the simplest block and then create a post, add the block and save. Then copy the block, create a new post, paste the block into the new post and save. Then view post 1 and then post 2. Post 2 will display post 1's id.
block.json
{ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "meta-box/wtr-id", "title": "WTR ID", "description": "Displays the WTR id.", "keywords": [ "wtr", "id" ], "supports": { "customClassName": true }, "attributes": { "element_type": { "enum": [ "span", "div" ] } }, "render": "file:./block.php" }Field definitions:
function wtr_id_field_settings( $meta_boxes ) { $meta_boxes[] = array( 'id' => 'wtr-id', 'title' => 'WTR ID Field Content', 'type' => 'block', 'fields' => array( array( 'id' => 'element_type', 'name' => 'Text Element Type', 'type' => 'select', 'options' => array( 'span' => 'span', 'div' => 'div', ), ), ), ); return $meta_boxes; } add_filter( 'rwmb_meta_boxes', 'wtr_id_field_settings' );Render file block.php:
<?php echo get_the_ID();May 9, 2026 at 10:44 PM #49958Peter
ModeratorHello Richard,
Thanks for reaching out.
I can see the issue when previewing the post only. If you publish the post and visit post page in the frontend, it won't display the caching issue. Can you please confirm this on your end?
May 9, 2026 at 11:05 PM #49959Richard Coy
ParticipantThe cache is displaying on the front end, the cache is not used in the editor. The code in your plugin is very simple and direct and makes it obvious the cache is not used in the editor but is used everywhere else:
/meta-box-aio/vendor/meta-box/mb-blocks/src/Loader.php:101
`
$is_editor = defined( 'REST_REQUEST' ) && REST_REQUEST && isset( $_GET['context'] ) && $_GET['context'] === 'edit';// Generate cache key based on block ID and attributes for non-editor requests.
$cache_key = null;
if ( ! $is_editor ) {
$cache_key = 'mbb_render_' . $meta_box->id . '_' . md5( wp_json_encode( $attributes['data'] ?? [] ) );
$cached = wp_cache_get( $cache_key, 'mb-blocks' );
if ( $cached !== false ) {
return $cached;
}
}
`
The cache seems to clear on post save some times and also only has a 5 minute lifespan, but it's long enough to cause all kinds of trouble.If you publish both posts and then view them subsequently, you will see the issue plainly.
May 9, 2026 at 11:07 PM #49960Richard Coy
ParticipantThe issue is very obvious, the plugin is using static data to cache dynamic data, this will never work reliably.
-
AuthorPosts
- You must be logged in to reply to this topic.