chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
64.88k stars 11.93k forks source link

chart.js (2,3,4,master) do not work on evironments loading also prototype.js #11201

Open judovana opened 1 year ago

judovana commented 1 year ago

Expected behavior

The chart.js library will render the chart even if prototype.js is loaded.

Current behavior

Reproducer page: https://jvanek.fedorapeople.org/charts/ ; namely: https://jvanek.fedorapeople.org/charts/impl/index4-umd-deprototyped.html

I maintain set of jenkins plugins, built around chartjs1. Finally (!) I kicked myself lot enough to port them to chart.js 4, thus I set this page to track the migration 1->2->3-4. At the end, I finished only 4, as it was very smooth.

Unluckily, when I finished the migration, I found the chart is not showing properly in jenkins, although identical page shows properly outside jenkins. I found, that loading of prototype.js http://prototypejs.org/ (in any version) is killing prototpye search in chart.js.

I debugged it to call of

  getPrototypeOf() {
      return Reflect.getPrototypeOf(scopes[0]);
    },

However, it seesm it is broken elsewhere, as without prototype.js scopes is array of length 2, but with prototype.js it is empty array. To found it reach over my JS skill.

Uncaught TypeError: `target` argument of Reflect.getPrototypeOf must be an object, got undefined
    getPrototypeOf helpers.config.js:57
    Ue helpers.config.js:181
    get helpers.config.js:205
    get helpers.config.js:120
    Xe helpers.config.js:188
    get helpers.config.js:119
    update core.controller.js:493
    wn core.controller.js:206
    <anonymous> index4-umd-deprototyped.html:89

Note, if you remove prototype.js from jenkins, the charts appear.But everything else case to work :)

Additional resources:

2017 mentions conflict with wordpress, solved by removal of prototype.js from project . Useless note, it is same trace I hit on chartj2 even with prototype.js 1.7 2018 mentions it on jenkinsci-dev group This mentions, update to 1.7.3 is fixing the issue. It did not worked for me relevant to above. PR to bump jenkins protype.js from 1.7 to 1.7.3. Caused issues, was reverted, afaik jenkins is still on 1.7 2019 stackoweeflow exact issue (with possible solution) 2020, github issue for chartjs. Not 100% related, by mention security issues and is about same function One of the few CVEs related to chart.js prototyep polution

Reproducible sample

https://jvanek.fedorapeople.org/charts/impl/index4-umd-deprototyped.html

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

4.2.1

Browser name and version

latest firefox and chromium

Link to your project

https://github.com/judovana/jenkins-chartjs-plugin

judovana commented 1 year ago

Added also editable reproducert: https://jsfiddle.net/yvs6u3w9/ x https://jsfiddle.net/p3fmz5ty/ If yo remove <script src="https://jvanek.fedorapeople.org/charts/impl/prototypejs/prototype.js-1.7" type="text/javascript"></script> the chart will reappear (or opposite if you add it, then it will disapear)

judovana commented 1 year ago

Had jsust checked against self built master of chart.js. Same issue

judovana commented 1 year ago

Have tried with tip of prototype.js; no change

judovana commented 1 year ago

for record: https://issues.jenkins.io/browse/JENKINS-70906