Possible plugin lifecycle regression in Chart.js 4.5.1 causing chartjs-plugin-datalabels to draw before internal labels are prepared
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 活跃
- 技术栈
- javascript
- 领域
- frontend
调研方向
从 src/core/core.plugins.js 开始,比较 Chart.js 4.5.0 和 4.5.1 之间 PluginService._init 及 notification 行为的差异。尝试根据报告中的配置构建一个最小的 chartjs-plugin-datalabels 2.2.0 复现,并跟踪 setup、update 和 draw hooks。确认或排除生命周期回归,并记录一个可复现的失败或一个针对性回归测试,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Expected behavior
After upgrading from Chart.js 4.5.0 to 4.5.1, charts using chartjs-plugin-datalabels 2.2.0 can fail during render with:
TypeError: can't access property "length", labels is undefined
The stack points into chartjs-plugin-datalabels.js during its draw/layout step, where it expects a prepared labels array.
The same chart configuration works with Chart.js 4.5.0.
Suspicious Chart.js change
The likely related change is in src/core/core.plugins.js.
In 4.5.0, PluginService initialized _init as an empty array:
constructor() {
this._init = [];
}
In 4.5.1, _init is initialized as undefined, and plugin notifications return early if beforeInit has not populated it:
constructor() {
this._init = undefined;
}
notify(chart, hook, args, filter) {
if (hook === 'beforeInit') {
this._init = this._createDescriptors(chart, true);
this._notify(this._init, chart, 'install');
}
if (this._init === undefined) {
return;
}
...
}
Hypothesis
Some plugin lifecycle notifications may be skipped, so chartjs-plugin-datalabels does not receive the update hooks it uses to build its internal label layout, but later still reaches its draw hook. That leaves its internal labels undefined and causes the crash.
Environment
Chart.js: 4.5.1
Working version: 4.5.0
Plugin: chartjs-plugin-datalabels 2.2.0
Browser: include browser/version if known
Chart type: include the failing chart type, e.g. bar/pie
Minimal symptom
The failing plugin line is equivalent to:
for (i = 0, ilen = labels.length; i < ilen; ++i) {
where labels is unexpectedly undefined.
Current behavior
Question
Was the PluginService._init === undefined guard intended to skip all plugin hooks before beforeInit, and could it cause inline/per-chart plugins such as ChartDataLabels to miss setup hooks but still receive draw hooks?
I tried to create a minimal CodePen using Chart.js 4.5.1 and chartjs-plugin-datalabels 2.2.0, but I have not been able to reproduce the error outside our REDCap page yet. The issue may depend on our page lifecycle or how the charts are created in that environment.
I understand this may not be actionable without a reproduction, but I wanted to ask whether the PluginService._init change in 4.5.1 could plausibly cause plugin setup hooks to be skipped while later draw hooks still run.
Reproducible sample
https://www.chartjs.org/dist/master/chart.umd.min.js
Optional extra steps/info to reproduce
No response
Possible solution
No response
Context
No response
chart.js version
v4.5.1
Browser name and version
No response
Link to your project
No response
- 主要语言
- JavaScript
- 星标
- 67.8k
- 派生
- 12k
- 平均合并
- 6 小时 15 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
chartjs/Chart.js 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Numeric tick formatter gives repeated labels in scientific notation and with bounds: 'data'可能已有人在做 @RClaudiuM 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
linear axis: "reverse" breaks tick align 'inner'可能已有人在做 @SrkianFardin25 于 6 天前认领。 未关闭type: bug
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
fill: 'stack': a dataset's whole fill disappears when its x differs from the line below by ≤ 1e-6 px (happens in animations)可能已有人在做 @ump45nose 于 42 天前认领。 未关闭type: bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
Legend pointStyle: 'line' does not apply dataset borderDash pattern可能已有人在做 @HuzaifaChaudary 于 75 天前认领。 未关闭type: bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
相似的 Issue
-
1️⃣ phase/under-investigation flaky/confirmed flaky/needs-decision type/bug
难度 2/5 1-3 小时 新手友好度 65/100
growilabs/growi#12246 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
TMHSDigital/Free-Game-Dev-Assets#301 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
-
📦 expo-router Android contributor: external needs review sdk-58 severity: medium
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 78/100
angrymrt/wiskunde-fit#117 ·
维护者通常 1 天内回复