Flexible Content + Tab field: collapsing a newly-added (unsaved) layout throws in _acf-field-tab.js and aborts field init (ACF PRO 6.8.3 / WP 7.0)
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
- 58/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu với assets/src/js/_acf-field-tab.js, đặc biệt là TabField.initialize() và các đường dẫn getTabs() và render() của tab-fields manager, sau đó tái hiện sự cố bằng field-group JSON tối thiểu được cung cấp. Theo dõi vòng đời collapse và re-render của Flexible Content để xác định lý do tab wrapper làm mất group instance của nó. Hoàn tất khi một layout mới được thêm có thể thu gọn và mở rộng mà không có TypeError, đồng thời các trường WYSIWYG của nó vẫn được khởi tạo và hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
On WordPress 7.0 + ACF PRO 6.8.3, collapsing a Flexible Content layout that was added in the current (unsaved) editing session throws two uncaught TypeErrors from the core tab-field JS (assets/src/js/_acf-field-tab.js). The first one aborts acf.getFields()'s init loop, so every field rendered after the tab group never initializes, in our case the WYSIWYG sub-fields inside the Flexible Content layouts. The layout can no longer be expanded and its editors are gone until the page is reloaded.
This only affects layouts added client-side in the current session. Collapsing layouts that were rendered server-side (after Save + reload) works perfectly. A field group needs at least one top-level Tab field plus a Flexible Content field to reproduce.
To Reproduce
- Create a field group with a
Tabfield ("Tab A"), a secondTabfield ("Tab B"), and aFlexible Contentfield with one layout containing a singlewysiwygsub-field (minimal JSON below). - Add a new post for the assigned post type.
- In the Flexible Content field, click Add Row and pick the layout.
- Click the new layout's handle to collapse it.
- Open the browser console.
Expected behavior
The layout collapses/expands and the fields inside it (including the WYSIWYG) keep working, exactly as they do for saved / server-rendered layouts.
Screenshots or Video
Both errors fire on the single collapse click:
Uncaught TypeError: Cannot read properties of undefined (reading 'addTab')
at TabField.initialize (acf-input.js)
at acf.newField -> acf.getField -> acf.getFields -> doAction()
Uncaught TypeError: Cannot read properties of undefined (reading 'get')
at render -> getTabs().map() (the tab-fields manager)
at doAction('append' | 'show' | 'refresh')
Code
Minimal repro field group:
{
"key": "group_repro_tab_fc",
"title": "Repro - tabs + flexible content",
"fields": [
{ "key": "field_repro_tab_a", "label": "Tab A", "name": "", "type": "tab", "placement": "top" },
{ "key": "field_repro_text_a", "label": "Text A", "name": "text_a", "type": "text" },
{ "key": "field_repro_tab_b", "label": "Tab B", "name": "", "type": "tab", "placement": "top" },
{ "key": "field_repro_fc", "label": "Blocks", "name": "blocks", "type": "flexible_content", "button_label": "Add Row",
"layouts": {
"layout_repro_text": {
"key": "layout_repro_text", "name": "text", "label": "Text", "display": "block",
"sub_fields": [
{ "key": "field_repro_body", "label": "Body", "name": "body", "type": "wysiwyg", "tabs": "all", "toolbar": "basic", "media_upload": 0 }
]
}
}
}
],
"location": [[{ "param": "post_type", "operator": "==", "value": "post" }]]
}
Version Information:
- WordPress 7.0
- PHP 8.4
- ACF PRO 6.8.3
- Chrome 148 (macOS). Reproduces with a stock theme; our theme JS does not touch ACF or TinyMCE.
Additional context - root cause (pinpointed to assets/src/js/_acf-field-tab.js)
After the collapse, a .acf-tab-wrap element stays in the DOM but loses its group instance: $wrap.data('acf') is now undefined. Two paths then dereference it.
TabField.initialize()runs again (collapse ->doAction->acf.getFields()->acf.newField->initialize). With a preceding wrap present it takes the "reuse" branch:
// L84-L91
if ( ! $tabs.length || settings.endpoint ) {
this.tabs = new Tabs( settings );
} else {
this.tabs = $tabs.data( 'acf' ); // L87 -> undefined (orphaned wrap)
}
this.tab = this.tabs.addTab( $tab, this ); // L91 -> throws: undefined.addTab
The throw is uncaught, so the enclosing getFields().map() loop aborts and no field after the tab group initializes. This is what kills the WYSIWYG editors.
- The tab-fields manager re-renders on
append/show/refreshand maps over every wrap in the document:
// L525-L534
getTabs: function () {
return acf.getInstances( this.findTabs() ); // L526 -> array containing undefined
},
render: function ( $el ) {
this.getTabs().map( function ( tabs ) {
if ( ! tabs.get( 'initialized' ) ) { // L531 -> throws: undefined.get
tabs.initializeTabs();
}
} );
},
Important: I tried defensively guarding both sites (try/catch around initialize, and filtering falsy values out of getInstances). That silences both console errors, but it does not restore the editors or the collapse/expand behaviour, the form state is already corrupted by then. So the underlying issue is that the PRO Flexible Content collapse / re-render leaves a .acf-tab-wrap without its data('acf') group (it should keep it bound, or re-bind on re-render). L87/L91 and L526/L531 are only where it surfaces; null-guarding them would mask the symptom, not fix it.
Possibly related: #986 (Flexible Content expand/collapse state).
Notes:
- The console line that often co-occurs,
Failed to load plugin url: .../wp-includes/js/tinymce/langs/<locale>.js, is unrelated and cosmetic: ACF already printstinymce.ScriptLoader.markDone(...)for that URL. The editor breakage is the tab crash above, not the TinyMCE language file. - Also reproduces with the post type's
editorsupport removed and a non-enadmin locale, but neither is required for the crash.
- 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