-
Notifications
You must be signed in to change notification settings - Fork 222
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
React 18 Flickering #684
Comments
Any updates on this? |
Has anyone been able to solve it? |
@Arnau-Gelonch I found a (very suboptimal) work-around for now. It's not perfect:
class StockChart extends React.Component<StockChartProps> {
idFromProps(): string {
return `candle-chart-${this.randomId}`;
}
componentDidUpdate(): void {
if (this.props.data.length === 0) {
return;
}
// if there is already a chart rendered, remove it
const element = document.getElementById(this.idFromProps());
if (this.hasRendered && element) {
ReactDOM.unmountComponentAtNode(element);
this.hasRendered = false;
}
if (!this.hasRendered) {
ReactDOM.render(this.internalRender(), document.getElementById(this.idFromProps()));
this.hasRendered = true;
}
}
componentDidMount(): void {
this.componentDidUpdate();
}
componentWillUnmount(): void {
const element = document.getElementById(this.idFromProps());
if (this.hasRendered && element) {
ReactDOM.unmountComponentAtNode(element);
}
}
public render() {
// use ReactDom.render to render the component
return <div id={this.idFromProps()} />;
}
public internalRender() {
// render your chart
}
} |
Leave |
Are there any updates on this? My company is looking to use this library in an upcoming product. We could possibly devote dev time to fixing. |
@carterjfulcher I would've thought this is already fixed, there is no flickering anymore (under React 17 rendering method) |
On React 18, panning and zooming still flickers. Tried avi2d method, doesn't work for me. By changing
in "node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@reac |
this is exactly what we are experiencing |
Is there any solution to this in next.js? |
This fixed the problem, Does it have any consequences? If not why is someone not creating a PR as this fixes the issue? |
@Cr1pter I resolved the issue in next.js with this suggestion, You can do these changes in the ChartCanvas.js present in the module. |
When running under React 18 the current version of the charts is flickering on mouse wheel operations. This appears to be due to React 18 batching updates originating from native event handlers. See https://react.dev/blog/2022/03/08/react-18-upgrade-guide#automatic-batching
We've tried using the recommend method of FlushSync to avoid the batching, whilst this does remove the flickering, it also produces an unacceptable level of performance and jerk.
The only workaround at the moment is to use
ReactDom.render
instead ofReactDom.createRoot().render
, this will mean the same behaviour as React 17 but with a warning in the console.The text was updated successfully, but these errors were encountered: