AdvancedCustomFields / AdvancedCustomFields/acf

ACF skips WP_Block::render for preview in Editor

Open
#745 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Issue:
It seems that ACF uses a custom AJAX action/callback for rendering block previews in the editor: acf_ajax_fetch_block and acf_rendered_block/acf_render_block directly.
On the frontend, the rendering of the block is done by WP cores render_block and WP_Block::render. This render functions call the following filters:

  • render_block_data
  • render_block_context
  • and they setup the WP_Block_Supports class which is required for get_block_wrapper_attributes to work.

This means, that when an ACF block is rendered in the editor, it does not call these hooks. We use render_block_data for some helpers and we also use get_block_wrapper_attributes much in our block templates (which does some block-supports magic and also adds the default block class name) - as suggested by WordPress core documentation.

Reproducing:

  1. Add a callback filter to render_block_data to change some block attributes data. See how it get's called when rendering a custom block on the frontend but not when the preview is rendered on the backend.
  2. Use get_block_wrapper_attributes in your block template. See how it works when rendering a custom block on the frontend but not when the preview is rendered on the backend. It even triggers a PHP warning.

Suggested fix: ACF should use render_block to render block previews so it's certainly the same output as on the frontend.

Version:
ACF Version: 6.0.3
WordPress Version: 6.0
PHP Version: 8.0
ACF Block-Version: 1 (via acf_register_block_type)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the acf_ajax_fetch_block callback and its acf_rendered_block/acf_render_block path, then compare it with WordPress render_block and WP_Block::render. Reproduce the preview and frontend cases using render_block_data and get_block_wrapper_attributes; done means the preview invokes the same filters and block-support behavior without the reported warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.