Duplicated ACF blocks do not reflect TinyMCE edits in editor preview
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript, php
Hướng nghiên cứu
Bắt đầu trong pro/blocks.php, xung quanh acf_get_block_id() tại dòng được báo cáo, và tái hiện trường hợp block bị nhân bản bằng block.json, block.php và trường WYSIWYG được cung cấp. Xác minh rằng các block bị nhân bản nhận cùng các IDs và rằng các thay đổi trong TinyMCE không cập nhật phần xem trước của trình chỉnh sửa; được xem là hoàn tất khi block bị nhân bản cập nhật theo thời gian thực mà không làm hỏng block gốc, bao gồm cả các trường WYSIWYG của repeater.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When an ACF block containing a WYSIWYG field is duplicated in the block editor, editing the
duplicated block's WYSIWYG field does not update the block preview in the editor. The content typed
in TinyMCE is not propagated to setAttributes({ data: ... }), so the preview remains stale.
This occurs because ACF generates the block ID via acf_get_block_id() using an MD5 hash of the
block attributes. Since the duplicated block has identical attributes to the original, both blocks
receive the same block ID. This causes the TinyMCE <textarea> elements in both block forms to share
the same id attribute (e.g. acf-block_abc123-field_xyz), resulting in TinyMCE instance conflicts.
The duplicated block's TinyMCE onChange handler fails to correctly call setAttributes, leaving the
block preview unchanged.
The frontend preview (via "Preview in new tab") renders correctly — the issue is limited to the
editor's real-time block preview.
To Reproduce
- Register an ACF block with a WYSIWYG field (e.g. b_content) and "mode": "edit" in block.json
- Open the block editor and add the block to a post
- Enter some text in the WYSIWYG field (e.g. "hello")
- Save the post
- Duplicate the block using the block toolbar (⋮ → Duplicate)
- Select the duplicated block
- Edit the WYSIWYG field in the sidebar or via the pencil icon toggle (edit mode → type new text →
switch back to preview mode) - Observe that the block preview still shows the original text ("hello"), not the newly entered
text
Expected behavior
The duplicated block's preview should update in real-time to reflect the content entered in the
WYSIWYG field, identical to how it works for the original (non-duplicated) block.
https://github.com/user-attachments/assets/45c9a76d-2bfc-47b9-aff9-347db71ba8eb
Code
Minimal block.json:
{
"name": "acf/example-wysiwyg",
"title": "Example WYSIWYG Block",
"category": "common",
"apiVersion": 3,
"acf": {
"mode": "edit",
"renderTemplate": "block.php"
},
"supports": {
"align": false
}
}
block.php:
<?php
$content = get_field('b_content');
if ($content) {
echo '<div class="example-block">' . $content . '</div>';
}
Field group: a single WYSIWYG field with name b_content assigned to the block.
Root cause analysis
acf_get_block_id() in pro/blocks.php (line ~1469) generates the block ID from
md5(wp_json_encode($attributes)). When a block is duplicated, $attributes (including data) is
identical, producing the same hash. This results in:
- Identical block IDs for both original and duplicate
- Identical <textarea> element IDs in both block forms (e.g. acf-block_<same_hash>-field_)
- TinyMCE instance collision — tinymce.get(id) returns the original block's editor instance,
preventing the duplicate's TinyMCE from correctly binding its onChange to setAttributes
The issue affects both the sidebar form (InspectorControls) and the inline edit mode form when
toggled via the pencil icon.
Current workaround
We implemented a JavaScript workaround that bypasses ACF's internal onChange pipeline entirely. It
listens for TinyMCE change/keyup events directly and calls
wp.data.dispatch('core/block-editor').updateBlockAttributes() to sync the content to the Gutenberg
store:
tinymce.on("AddEditor", function (evt) {
evt.editor.on("init", function () {
var el = evt.editor.getElement();
var dataKey = parseDataKeyFromTextareaName(el.name);
// e.g. "acf[block_xxx][note_items][0][note_text]" → "note_items_0_note_text"
evt.editor.on("change", function () {
var clientId = wp.data.select("core/block-editor").getSelectedBlockClientId();
var block = wp.data.select("core/block-editor").getBlock(clientId);
var newData = Object.assign({}, block.attributes.data);
newData[dataKey] = evt.editor.getContent();
wp.data.dispatch("core/block-editor").updateBlockAttributes(clientId, { data: newData });
});
});
});
This works but is a workaround — ideally ACF should ensure unique block IDs for duplicated blocks
(e.g. by incorporating the Gutenberg clientId into the hash, or forcing a new unique ID on
duplication).
Version Information:
- WordPress Version: 6.9
- PHP Version: 8.x
- ACF Version: ACF PRO 6.9.4
- Browser: Chrome (latest)
Additional context
- The issue also manifests with blocks that have WYSIWYG fields inside repeaters (e.g. a "mixed
notes" block with a repeater containing note_text WYSIWYG sub-fields) - Setting "autoInlineEditing": false in block.json prevents a related but separate issue where the
placeholder "Click to set content" appears instead of the preview - The issue does NOT occur with native Gutenberg blocks (e.g. Heading, Paragraph) since they don't
use ACF's block ID / TinyMCE pipeline - Upgrading apiVersion from 2 to 3 does not resolve the issue
- Ngôn ngữ chính
- PHP
- Star
- 946
- Fork
- 197
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của AdvancedCustomFields/acf
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1041 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
AdvancedCustomFields/acf#1038 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1034 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
AdvancedCustomFields/acf#1032 · 1 bình luận ·
-
Drop trap, acf_after_titleĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1029 · 1 bình luận ·
Tất cả issue của AdvancedCustomFields/acf
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
sync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sync-en
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Yoast/wordpress-seo#23658 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
fixed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
firefly-iii/firefly-iii#12934 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày