chartjs / chartjs/Chart.js

defaultView is null (Firefox and Chromium / chart.js 4.3)

Open
#11,355 3 comments 4 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

Code running without errors.

### Current behavior

When executing code, the following error occurs :
```
Uncaught TypeError: element.ownerDocument.defaultView is null
getComputedStyle helpers.segment.js:2161
getStyle helpers.segment.js:2163
readUsedSize helpers.segment.js:2351
initCanvas chart.js:3227
acquireContext chart.js:3381
Chart chart.js:5602
```

### Reproducible sample

None

### Optional extra steps/info to reproduce

_No response_

### Possible solution

Rewrite the function `getComputedStyle` in "chart.js/dist/chunks/helpers.segment.js:2161" as follow :
```
const getComputedStyle = (element)=>element.ownerDocument.defaultView?.getComputedStyle(element, null) ?? { getPropertyValue: () => null };
```

### Context

I had a code that worked, then I upgraded Chart.js npm package.

### chart.js version

v4.3.0

### Browser name and version

Firefox 113.0.2 / Chromium 114.0.5735.106

### Link to your project

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.