Possible plugin lifecycle regression in Chart.js 4.5.1 causing chartjs-plugin-datalabels to draw before internal labels are prepared
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Attiva
- Stack tecnologico
- javascript
- Ambito
- frontend
Direzione di ricerca
Inizia in src/core/core.plugins.js confrontando il comportamento di PluginService._init e delle notifiche tra Chart.js 4.5.0 e 4.5.1. Prova a creare una riproduzione minima con chartjs-plugin-datalabels 2.2.0 a partire dalla configurazione segnalata e traccia gli hook setup, update e draw. Il lavoro è completato quando la regressione del ciclo di vita è confermata o esclusa e viene documentato un errore riproducibile o un test di regressione mirato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- JavaScript
- Stelle
- 67.8k
- Fork
- 12k
- Merge medio
- 6h 15m
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di chartjs/Chart.js
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Numeric tick formatter gives repeated labels in scientific notation and with bounds: 'data'Forse già presa @RClaudiuM l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
linear axis: "reverse" breaks tick align 'inner'Forse già presa @SrkianFardin25 l’ha presa 6 giorni fa. Apertatype: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
fill: 'stack': a dataset's whole fill disappears when its x differs from the line below by ≤ 1e-6 px (happens in animations)Forse già presa @ump45nose l’ha presa 42 giorni fa. Apertatype: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Legend pointStyle: 'line' does not apply dataset borderDash patternForse già presa @HuzaifaChaudary l’ha presa 75 giorni fa. Apertatype: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di chartjs/Chart.js
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
TMHSDigital/Free-Game-Dev-Assets#301 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
-
📦 expo-router Android contributor: external needs review sdk-58 severity: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
expo/expo#53436 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
angrymrt/wiskunde-fit#117 ·
I maintainer di solito rispondono entro 1 giorno
-
Poll votes are not receivedAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
raulpetruta/ha-wa-bridge#62 ·