Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser Console: [ECharts] There is a chart instance already initialized on the dom. #37

Open
1 of 3 tasks
robertgz opened this issue Jul 2, 2024 · 17 comments
Open
1 of 3 tasks
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@robertgz
Copy link

robertgz commented Jul 2, 2024

Description

I am seeing a browser console messages when a component containing the EChart is rendered multiple times while the chart is initializing. I am not sure if this is an issue or if I need to change how I use the EChart component.

The console message I see when using Chrome is:
[ECharts] There is a chart instance already initialized on the dom.

Link to Reproduction

https://stackblitz.com/edit/stackblitz-starters-6kgmdx?file=app%2Fpage.tsx

Steps to reproduce

  1. Open the Stackblitz
  2. Click Open Preview in a new tab at the top right of stackblitz and click on Connect to Project in the new tab/window.
  3. Open the browser Console for the new tab/window.
  4. The tab/window with the Preview may need to be refreshed a few times to see the message in the browsers Console.

JS Framework

Next.js 13 (TS)

Version

1.2.0

Browser

Google Chrome 126

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

If the number used in setInterval is increased from 200 to 2000 the console message does not show.

@hugocxl
Copy link
Owner

hugocxl commented Aug 12, 2024

@robertgz fixed in 1.2.1

@hugocxl hugocxl closed this as completed Aug 12, 2024
@toshiya14
Copy link

@robertgz fixed in 1.2.1

Still appears in 1.4.0

@hoeflerjo
Copy link

hoeflerjo commented Oct 9, 2024

This issue appears not to be solved.
Like @toshiya14 it also still happens to me for most Charts without apparent reason.
I found out this only accures on the first render when the chart is rerendered the chart appears.
So my current solution: I use the useEffect hook without parameters and make a timeout with 1ms delay that just somehow triggers a rerender. In my case by just useing the next best useState I found.
Like this:

const [value, setValue] = useState(0);
useEffect(() => {
    setTimeout(() => {
      setValue(value);
    }, 1);
  });

But this is propably the dirtiest quick fix I came up with and I hate it.

Addition: the setValue forcing a rerender must also be a dependency in the Chart instance to force the rerender there.

@hugocxl hugocxl reopened this Oct 9, 2024
@piotrzarzycki21
Copy link

I can confirm. I'm experiencing same issue here. Any chance it will be fixed ?

@hugocxl
Copy link
Owner

hugocxl commented Oct 21, 2024

Hi guys, I am currently really busy and I cannot dedicate much time to solve it. It'd great if you could take a look (I can provide details for those who are interested).
I am planning on releasing a v2.0 with a fresher API in the upcoming future, but currently I am not getting much time to dedicate to the lib. Sorry for the inconveniences 🙏

@hugocxl hugocxl added bug Something isn't working help wanted Extra attention is needed labels Oct 21, 2024
@piotrzarzycki21
Copy link

Workaround from @hoeflerjo worked, but definitely I would love to look and see if I can provide PR. :)

@piotrzarzycki21
Copy link

If you could point me to the right direction @hugocxl or if you won't have time I will try to figure out myself what is going on, but it will be probably super slowly ;)

@hugocxl
Copy link
Owner

hugocxl commented Nov 2, 2024

@piotrzarzycki21 sure. Whenever the init function is called the ECharts instance gets initialized.

return init(containerRef.current, theme, {

I tried disposing when the component unmounts (well I tried several options to do this, nothing worked), but somehow the instance does not get discarded. Therefore, next time init is called that warning is thrown.

Not sure what I'm missing here 😕

@piotrzarzycki21
Copy link

@piotrzarzycki21 sure. Whenever the init function is called the ECharts instance gets initialized.

return init(containerRef.current, theme, {

I tried disposing when the component unmounts (well I tried several options to do this, nothing worked), but somehow the instance does not get discarded. Therefore, next time init is called that warning is thrown.

Not sure what I'm missing here 😕

Thank you! :) I will dive into that, won't be quick since I'm busy as well, but this warning drive me crazy in our app. ;)

@brandanking-decently
Copy link
Contributor

brandanking-decently commented Nov 27, 2024

@hugocxl I have implemented a solution to this in the PR I created.

const setContainerRef = async (node: T) => {
    if (!node || node === containerRef.current) return;
    if (echartsRef.current) echartsRef.current.dispose();

    containerRef.current = node;
    echartsRef.current = await setupECharts(node, options);
    resizeObserverRef.current = startResizeObserver();

    setStarted(true);
};

@piotrzarzycki21
Copy link

Awesome @brandanking-decently !! Thank you! I run out of time to look into that. I hope it will be merged.

@brandanking-decently
Copy link
Contributor

Still waiting for an update on this getting reviewed. Hopefully soon as this is starting to be a blocker for us

@amarant
Copy link

amarant commented Dec 18, 2024

@brandanking-decently Maybe you can publish your fork on npm if the maintainer is not responsive ?

@hugocxl
Copy link
Owner

hugocxl commented Dec 19, 2024

Merged and published @brandanking-decently's PR under v1.4.1. Thanks for having the time to look into this 🙏🏻

@amarant
Copy link

amarant commented Dec 19, 2024

There seems to be a problem with the release :

[plugin:vite:import-analysis] Failed to resolve entry for package "@kbox-labs/react-echarts". The package may have incorrect main/module/exports specified in its package.json.

There is no index.mjs in the dist directory as specified in the module section of the package.json.

@hugocxl
Copy link
Owner

hugocxl commented Dec 20, 2024

@amarant published a patch. Should be solved now

@amarant
Copy link

amarant commented Dec 20, 2024

@hugocxl yes it works fine now, thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants