Cannot read properties of null (reading 'ownerDocument') in getComputedStyle when canvas is detached during a pending debounced resize
I maintainer di solito rispondono entro 1 giorno
@Yahiro025 ci sta già lavorando.
Dal 18/9/2026.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 58/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, typescript
Direzione di ricerca
Start in helpers.dom.ts and platform.dom.js, tracing getComputedStyle and getMaximumSize through Chart._resize and the debounced resize callback. Compare the proposed guards with the approach from #11809 and check the related getContainerSize and getRelativePosition paths. Done means a detached canvas during pending resize or teardown no longer throws the reported ownerDocument error.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
getStyle/getComputedStyle in helpers.dom.ts (called via getMaximumSize → DomPlatform.getMaximumSize) assumes the canvas element passed to it is never null. When a chart's canvas has already been removed from the DOM but resize()/update() still fires afterward, this throws:
TypeError: Cannot read properties of null (reading 'ownerDocument')
Stack (minified names resolved from source):
getComputedStyle (helpers.dom.ts)
→ getMaximumSize (helpers.dom.ts)
→ DomPlatform.getMaximumSize (platform.dom.js)
→ Chart._resize
→ Chart.detached
→ bindResponsiveEvents
→ bindEvents
→ _checkEventBindings
→ Chart.update
→ this._doResize (debounced resize callback)
Reproduction path
We hit this in a React app (via react-chartjs-2) using resizeDelay (a debounced resize). Sequence:
- Chart mounts; the constructor's resize path schedules a debounced
_doResizebecauseresizeDelay > 0. - Before that debounce timer fires, the component unmounts and React removes the canvas from the DOM (
destroy()runs, but the pending timer isn't always guaranteed to lose its race depending on framework/container teardown order). - The debounced callback fires anyway,
update()→_doResize→detached()→bindResponsiveEvents()→platform.getMaximumSize(canvas, ...)→getComputedStyle(canvas), andcanvasisnull/detached at this point →element.ownerDocumentthrows.
Prior art
This is the same failure #11809 (https://github.com/chartjs/Chart.js/pull/11809) fixed, reported against chart.js 4.4.3. That PR was closed without merging — not because the approach was rejected outright (a maintainer only commented the "return semi-default values" approach felt a bit hacky and asked whether the repro could be narrowed to the container-removal case), but because the author's team moved away from Chart.js before the discussion concluded. The underlying bug was never fixed.
We independently reproduced the identical stack trace and error message against the current latest release, chart.js 4.5.1, confirming it is still present.
Our workaround
We removed our own use of resizeDelay entirely, since a debounced resize is what creates the race between "component removed" and "debounced resize still pending." That avoids the crash for us, but the underlying null-check gap in getComputedStyle/getMaximumSize (and the related spots #11809 touched: getRelativePosition, getContainerSize) remains for anyone else hitting a similar teardown race through a different path (e.g. responsive: true without resizeDelay, combined with fast unmounts during an in-flight ResizeObserver callback).
Suggested fix
Re-open/revive the approach from #11809: guard getComputedStyle/getMaximumSize/getContainerSize/getRelativePosition against a missing canvas (optional chaining + sensible defaults), as that PR's diff already implements.
Environment
- Chart.js: 4.5.1
- Browser: reproduced in Chromium (Playwright) and in production (real user reports, Chrome/Edge on Windows)
- Lingua principale
- JavaScript
- Stelle
- 67.8k
- Fork
- 12k
- Merge medio
- 1g 12h
- PR unite (30g)
- 5
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
-
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 28 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 61 giorni fa. Apertatype: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
`skipNull` is a configuration option, not a dataset fieldForse già presa @puneetdixit200 l’ha presa 147 giorni fa. Apertatype: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
chartjs/Chart.js#12235 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
type: enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di chartjs/Chart.js
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
bug documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
awslabs/visual-asset-management-system#880 ·
I maintainer di solito rispondono entro 1 giorno
-
04 type: enhancement 33 needs: docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
plone/volto#8495 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG]: Workspace settings forms stay at 50% width on narrow screens and wrap text word by wordApertapossible bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Mintplex-Labs/anything-llm#6889 ·
I maintainer di solito rispondono entro 1 giorno