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

egui_text_agent is not removed from the dom when WebRunner.destroy() is called. #3618

Closed
LiamPClancy opened this issue Nov 24, 2023 · 1 comment · Fixed by #4561
Closed
Labels
bug Something is broken web Related to running Egui on the web

Comments

@LiamPClancy
Copy link

LiamPClancy commented Nov 24, 2023

Describe the bug
I'm loading a WASM package into a a react app, it's using egui to render the plot and rust to do logic.
when calling wasmHandle.start(...)
it adds the text agent with
super::text_agent::install_text_agent(self)?;

but when calling
wasmHandle.destroy()
the text_agent is not removed from the dom,
This is creating an issue if the wasmHandle.start(...) is called again.

my use case is that when someone logs out the wasmHandle is destroyed, and if they log back in again then .start is called.
i'm handling this by removing the egui_text_agent when the user logs out, but it'd be better i think if it was part of the destroy method.

I'm thinking to add

pub fn remove_text_agent() -> Result<(), JsValue> {
    if let Some(element) = web_sys::window()
        .unwrap()
        .document()
        .unwrap()
        .get_element_by_id(AGENT_ID)
    {
        if let Some(parent) = element.patent_node() {
            patent.remove_child(&element)?;
        }
    };

    Ok(());
}

to the text_agent.rs

and then modifying webRunner destroy with a call to remove_text_agent()

pub fn destroy(&self) {
        self.unsubscribe_from_all_events();
        super::text_agent::remove_text_agent()?;
        if let Some(runner) = self.runner.replace(None) {
            runner.destroy();
        }
    }

Happy to make a PR if you think the above is the correct approach?

@LiamPClancy LiamPClancy added the bug Something is broken label Nov 24, 2023
@emilk emilk added the web Related to running Egui on the web label Nov 24, 2023
@emilk
Copy link
Owner

emilk commented Nov 24, 2023

Sounds good - please make a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken web Related to running Egui on the web
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants