svgdotjs / svgdom

Straightforward DOM implementation to make SVG.js run headless on Node.js
MIT License
269 stars 53 forks source link

`window.NodeList.prototype.reduce` is `undefined` #105

Closed KermanX closed 1 year ago

KermanX commented 1 year ago

https://github.com/svgdotjs/svgdom/blob/cde873e869ad57d772fda593fa2a8b125fac6871/src/utils/bboxUtils.js#L46

Here window.NodeList.prototype.reduce is used, but AFAIK, there is no definition of it in MDN.

The issue is exposed especially when running SVGDOM with JSDOM.

Fuzzyma commented 1 year ago

Read the last sentence in the readme and it begins to make sense :D.

This Dom implementation is not 100% to spec. If you encountered an error, create a reproduction so I can fix the bug. Just positing an error message doesn't help that much :D

KermanX commented 1 year ago

I'm sorry that I carelessly haven't seen the last sentence in the readme.

You can reproduce the error via the following steps:

  1. Clone https://github.com/KermanX/node-mermaid/
  2. comment src/index.ts L56-L64
  3. run the exported render function.

However, I personally think that it isn't a must to reproduce the error, because the error in the above case is simple: svgdom/src/utils/bboxUtils.js Line46 uses window.NodeList.prototype.reduce, but jsdom doesn't implement it.

Thanks for your help.

Fuzzyma commented 1 year ago

You are somehow mixing 2 dom libraries and expecting it to work. It most likely wont. The bug you encounter is because jsdom expects a dom created by jsdom

KermanX commented 1 year ago

Thanks for your help. I mixed two libraries because I want to use svgdom as a polyfill for running mermaid in jsdom, nodejs. I opened this issue just wondering if it is a mistake. Since it now turned out to be not, I am closing the issue.

KermanX commented 1 year ago

😀