-
Notifications
You must be signed in to change notification settings - Fork 620
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
echarts-for-react + suspense = warning in dev and sometime blank graphic #466
Comments
Hi @astik , I think your issue belongs in: https://github.com/apache/echarts This repo offers a wrapper around the core |
Yes and no in fact ... Problem is inside echarts as i said in my original message. They know the problem and an issue has been solved (apache/echarts#10478). They usually end up in reloading the graph once it cames into view (when changing tabs for example). Still, in my case, the problem occurs when application suspends which is a React only topic. So we need a way to wrap this issue by :
In either way, this is a react only issue which needs to be done in this wrapper (as echart comes with this constraint). |
After digging a little, i found some relative issues:
To sum it up, suspense wraps DOM code in a div with Will try tomorrow morning =) |
Good news, it works as expected with React 18.0.0-rc0: https://stackblitz.com/edit/react-fa1hka Difference with previous example running React 17.0.2:
Of course, React 18 is not yet for production, so we'll have to wait as there is no fix scheduled for React 17 =/ This is not a bug in echarts-for-react but this is a limitation to know of ECharts+React17+Suspense. |
Should be fixed in React 18. |
I got the same issue with React 18 in my Jest unit tests. import { render } from "@testing-library/react";
render(<div style={{ width: "400px", height: "400px" }}><App /></div>);
// where <ReactECharts/> is included in the App. Even though the size is set as a parent div, it still doesn't help, Dependencies: "react": "^18.2.0",
"react-dom": "^18.2.0",
"echarts": "^5.4.1",
"echarts-for-react": "^3.0.2",
"@testing-library/react": "^13.4.0", In addition, if I set this in the <ReactECharts option={option} style={ { width: "300px", height: "300px" } } |
I tried a couple of ways in Jest unit tests, and came up with an solution to overload // In setupTests.ts.
import * as echarts from "echarts";
import ReactECharts from "echarts-for-react";
ReactECharts.prototype.getEchartsInstance = function (): echarts.ECharts {
const _this = this as any;
const e = _this.echarts; // Access the protected property.
// Explicitly add width and height in opts.
const opts = { width: "400px", height: "400px", ..._this.props.opts };
return (
e.getInstanceByDom(_this.ele) || e.init(_this.ele, _this.props.theme, opts)
);
}; Then, the warning has gone in my tests. |
If graphic renders while application is suspended, we get a warning:
It is coming from echarts:
As application is suspended, dom.clientWidth and dom.clientHeight are not available. So, even though it is a echarts warning it is an issue in a React context.
This would not be a problem if it was just this warning in dev mode (even though it is quite annoying =P). Sometimes the graph is not displayed at all, leaving a whole blank block.
Resizing the window does fill in the blank block with the correct graph.
Here is a sandbox to witness the warning: https://stackblitz.com/edit/react-yquxci. I used react-query to simulate lag in order to trigger Suspense.
What would be great: having the graph render paused while in Suspend mode in order to avoid the warning and the potential blank block. Or a way to refresh the block after suspense is done suspending.
The text was updated successfully, but these errors were encountered: