Possible plugin lifecycle regression in Chart.js 4.5.1 causing chartjs-plugin-datalabels to draw before internal labels are prepared
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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 フックを追跡します。ライフサイクルのリグレッションを確認または除外し、再現可能な失敗または焦点を絞ったリグレッションテストを文書化できれば完了です。
索引モデルが 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分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信
chartjs/Chart.js の issue をすべて見る
似ている issue
-
難易度 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 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
raulpetruta/ha-wa-bridge#62 ·