Editor performance issues when trying to load complex ACF groups on blocks
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, jquery, php, wordpress
- 领域
- frontend, performance
调研方向
使用链接 gist 中的 theme functions.php 块、字段组和文章内容重现该情况,然后分析块在侧边栏中打开时的初始化过程。先从报告中描述的 true_false 渲染路径和基于 Select2 的 select 初始化开始,重点关注重复的样式重新计算。完成标准是:复杂的 ACF 块字段能够初始化,且不会导致浏览器阻塞数秒。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
ACF is blocking the browser when attempting to initialize the editor fields for ACF block with complex field group and a lot of content inside of it.
This "blocking" is only happening when trying to initialize the block's fields after the page was already loaded. Also, blocking time is way smaller on Firefox.
To Reproduce
Reproduction requires the ACF & ACF Pro plugins to be installed.
- Register the dummy block inside the theme's functions.php using the snippet in the gist
- Import the field group from the gist
- Create the new page and insert the content provided in the gist
- Once page is saved, switch the block to the "preview" mode.
- Reload the page, wait for the editor page to load
- Click on the block to open its editor in the right sidebar
- Field group will try to initialize, blocking the browser for several seconds (~6s on my machine).
- After this initial blocking, editor functions normally
Expected behavior
Block fields groups should load near-instantly without blocking the whole browser for several seconds.
Screenshots or Video
Video preview of the lag when clicking on the ACF block and loading the field group:
https://github.com/user-attachments/assets/7ae1f0e8-45b2-41f3-a45c-099ed211700b
Using Chrome DevTools, I've captured the following monstrosity of the "Long Task":
Code
ACF field group, code for creating the dummy block and the content of the page required for reproduction can be found in this gist: https://gist.github.com/koloml/00a529c3ce935753c5e481b0c1898ab3
Version Information:
- WordPress Version: 6.8.1
- PHP Version: 8.2.27
- ACF PRO Version: 6.5.0.1
- Browser: Chrome 139
Additional context
I've tried to analyze the profile results. As you might have seen, the issue lies in the styles recalculation constantly being triggered while field group is rendering itself. Some fields are editing the styles, invalidating the browser internal caches related to styling. Then other fields are requesting the browser to calculate some properties which are dependent on the styling. Browser then recalculates styles and fields are invalidating the styles again.
Here are my attempts to pin-point the causes of the issues from the reproduction.
Checkbox (true_false) on render() is trying to calculate width of .acf-switch-on and .acf-switch-off. JQuery then attempts to get this width and causes browser to recalculate styles. Resulting width is added to inline styles.
Selector (select) with stylized UI enabled is initializing Select2 instance. During dropdown initialization, Select2 tries to subscribe to mousewheel events. This triggers special hook which calculates the line height for the options. During the calculation, it tries to request the font size on one of the parent elements.
I'm pretty sure this does not cover all blocks that cause this issue. I think, at least the fields which are based on Select2 or which are using jQuery in some way might also trigger unnecessary styling recalculations.
- 主要语言
- PHP
- 星标
- 948
- 派生
- 198
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 于 11 天前认领。 未关闭
难度 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 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1041 · 1 条评论 ·
-
True / False ACF control bug on RTL layouts可能已有人在做 @elicohenator 于 33 天前认领。 未关闭
难度 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 于 45 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
AdvancedCustomFields/acf#1032 · 1 条评论 ·
查看 AdvancedCustomFields/acf 的全部 Issue
相似的 Issue
-
good first issue ux
难度 1/5 1 小时以内 新手友好度 89/100
alleyinteractive/wp-curate#498 ·
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
mollie/PrestaShop#1593 ·
维护者通常 7 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
升级 PHP 8.5 后报错未关闭
难度 2/5 1-3 小时 新手友好度 62/100
-
Update Support Monitor URL to monitor.fueled.dev可能已有人在做 @claytoncollie 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
10up/10up-experience#241 ·