Skip to content

feat: add dispose_chart method for Echarts and Leptos integration#217

Open
MingleHeart wants to merge 2 commits into
yuankunzhang:mainfrom
MingleHeart:main
Open

feat: add dispose_chart method for Echarts and Leptos integration#217
MingleHeart wants to merge 2 commits into
yuankunzhang:mainfrom
MingleHeart:main

Conversation

@MingleHeart

Copy link
Copy Markdown

Source of the issue

Within the Leptos framework, encapsulating Chart-related components and using Custom::renderItem may cause the reused component to display residual custom content from the previous instance.

Solution

This pull request adds support for properly disposing of chart instances in the WasmRenderer, which is especially useful for freeing up resources in dynamic web applications, such as those built with Leptos. The main changes include introducing a dispose_chart method, exposing the underlying dispose method of the Echarts type to Rust, and ensuring thread safety for Echarts by implementing Sync and Send.

New chart disposal support:

  • Added the dispose_chart method to WasmRenderer, allowing users to explicitly dispose of chart instances and providing detailed documentation and usage examples, including integration with Leptos's on_cleanup lifecycle.

WebAssembly interop and thread safety:

  • Exposed the dispose method of the JavaScript Echarts object to Rust via wasm_bindgen, enabling the actual disposal logic to be called from Rust code.
  • Implemented Sync and Send for the Echarts type, making it possible to safely share Echarts instances across threads, which is important for concurrent or async Rust web applications.

PanagiotisS added a commit to PanagiotisS/charming that referenced this pull request Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant