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)
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 58/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- javascript
- 領域
- frontend
調査の方向性
assets/src/js/_acf-field-tab.jsから始め、特にTabField.initialize()とtab-fields managerのgetTabs()およびrender()の経路を確認してから、提供された最小のfield-group JSONで問題を再現します。Flexible Contentのcollapseと再レンダーのライフサイクルを追跡し、tab wrapperがgroup instanceを失う理由を特定します。新しく追加したlayoutがTypeErrorなしで折りたたみと展開を行え、そのWYSIWYGフィールドが引き続き初期化されて動作すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- PHP
- スター
- 948
- フォーク
- 198
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
AdvancedCustomFields/acf のほかの issue
-
PHP 8.5: "Using null as an array offset" deprecation in ACF_Data::is() when rendering a block with empty data (local-meta.php is_request)対応中かも @faisalahammad が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
AdvancedCustomFields/acf#1044 ·
-
is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)対応中かも @faisalahammad が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1041 · コメント 1 件 ·
-
True / False ACF control bug on RTL layouts対応中かも @elicohenator が 29 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
AdvancedCustomFields/acf#1038 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1034 · コメント 3 件 ·
-
Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+対応中かも @antwonw が 41 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
AdvancedCustomFields/acf#1032 · コメント 1 件 ·
AdvancedCustomFields/acf の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
verbb/formie#3022 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Automattic/blocks-engine#3090 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
macOS
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
beyondcode/herd-community#1771 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100