rustwasm / gloo

A modular toolkit for building fast, reliable Web applications and libraries with Rust and WASM
https://gloo-rs.web.app
Apache License 2.0
1.78k stars 147 forks source link

Error `closure invoked recursively or after being dropped` when opening `ObjectUrl` via `window().open_with_url()` #465

Open fabianboesiger opened 7 months ago

fabianboesiger commented 7 months ago

Describe the Bug

When opening a file via ObjectUrl and window().open_with_url(), the file is opened but the following error is thrown in the console:

Uncaught Error: closure invoked recursively or after being dropped

Steps to Reproduce

Use the following code snippet to open a file.

pub fn download_file(name: &str, contents: &[u8], mime_type: Option<&str>) -> Result<(), Error> {
    let file = gloo::file::File::new_with_options::<&[u8]>(name, contents, mime_type, None);
    let object_url = gloo::file::ObjectUrl::from(file);
    let download_url = Box::leak(object_url.to_string().into_boxed_str());

    gloo::utils::window()
        .open_with_url_and_target(download_url, "_blank")
        .unwrap();

    Ok(())
}