React Advanced Chart Example in Documentation has bug when removing chart during resizing #1429
Labels
bug
Unexpected problem or unintended behavior.
documentation
Improvements or additions to the documentation
needs investigation
Needs further investigation.
Milestone
Lightweight Charts™ Version: 4.0.1
Steps/code to reproduce:
Copy advanced react example from Lightweight Chart docs
Actual behavior:
When copying the Advanced React chart example that uses Refs and splits the Chart, Container, and Series into individual components, it doesn't work. An error is thrown when trying to remove the chart.
In development mode, React will run all useEffects and useLayoutEffects, then run their clean-up functions, then re-run the effects. There are some bugs in the clean-up functions which caused the example to not run properly.
The error occurred when
chart.remove()
was called in theuseLayoutEffect
hook that was responsible for handling resizing of the chart.Expected behavior:
The example should work out of the box.
The example posted on the website should include proper clean-up functions. The solution was to add
this._api = null;
in thefree()
functions for both the ChartContainer and Series components.The text was updated successfully, but these errors were encountered: