Hexastack / eazychart

EazyChart is a reactive chart library 📈, it allows you to easily add SVG charts in your React and Vue web applications.
https://eazychart.com
MIT License
21 stars 13 forks source link

Issue with React deployments - Segments does not support... #107

Closed mmontesinoademero closed 1 year ago

mmontesinoademero commented 1 year ago

Everything works great in development, but when deploying my React app, the app is throwing the error "Segments does not support non ordinal color scale" due to the deployed eazychart.esm.js, specifically the call to...

if("ScaleOrdinal"===a.constructor.name)

...which corresponds to line 35 at ez-react/src/components/Segments.tsx.

If I change this to...

a instanceof ScaleOrdinal (eazychart.esm.js) or colorScale instanceof ScaleOrdinal (Segments.tsx)

...then everything works as expected. I've not yet dug into see if this is related to my own Babel/Webpack configuration. I've been using the same deployment scripts for many years and never seen anything like this.

marrouchi commented 1 year ago

Hello @mmontesinoademero, thanks for reporting this, we will address the issue as soon as possible :)

marrouchi commented 1 year ago

If I remember correctly we had a typescript issue when using :

a instanceof ScaleOrdinal (eazychart.esm.js)
or
colorScale instanceof ScaleOrdinal (Segments.tsx)
marrouchi commented 1 year ago

@mmontesinoademero The root cause for this issue is well detailed here : https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript

The OrdinalScale class extends the AstractScale class and when we perform an "instanceof", in storybook preview :

const scale = new ScaleOrdinal( ... );
console.log(scale instanceof ScaleOrdinal); // prints false
console.log(scale instanceof AbstractScale); // prints true 

This seems to be an issue if when the compilation target is ES3 or ES5, but the wierd thing is that the configured target we have is ESNEXT. "Storybook" relies on Babel and does not account apparently for that config.

TL;DR We did remove the type safeguard for the moment so that we would think of a better way to handle this in the future : https://github.com/Hexastack/eazychart/pull/108 a new release is on the way ;)

marrouchi commented 1 year ago

@mmontesinoademero A new version 0.3.1-alpha.0 has been published, please let us know if you encounter other issues :)