seed icon indicating copy to clipboard operation
seed copied to clipboard

Mount takeover behavior concerns.

Open AlterionX opened this issue 6 years ago • 3 comments

The code in question is introduced in PR #276.

A new enum MountType was introduced for dealing with how to handle elements that are already attached to the root element (the mount_point). The behavior of MountType::Append is approximately the same as before the change. The behavior of MountType::Takeover is that it will add preexisting nodes to the tree, delete the underlying DOM nodes, then construct new DOM nodes.

The second is a little problematic. It is problematic because there can be nodes that should not be recreated (like script nodes). It also replaces unknown elements with the span element, which may also be problematic if someone has custom tags.

Additionally, the tag checking mechanism is slightly buggy, as the many tags have an upper case letter in their spellings, causing scripts to be removed from the DOM. The tag names are listing in dom_types.rs.

Lastly, this is also a bit inefficient, but it is a one time cost.

These issues might need to be addressed later.

AlterionX avatar Nov 03 '19 14:11 AlterionX

Here's a reproducible example based on counter example from the latest master:

// ... snip

fn before_mount(_: Url) -> BeforeMount {
    BeforeMount::new()
        .mount_point(seed::body())
        .mount_type(MountType::Takeover)
}


#[wasm_bindgen(start)]
pub fn render() {
    seed::log!("Started");
    App::builder(update, view).before_mount(before_mount).build_and_start();
}

You will see "Started" printed 2 times, while it should be printed only once.

TatriX avatar Jan 14 '20 22:01 TatriX

Warning about scripts in the mount point: https://github.com/seed-rs/seed/pull/334/files

MartinKavik avatar Jan 15 '20 14:01 MartinKavik

Does #478 close this issue?

Ben-PH avatar Dec 10 '20 17:12 Ben-PH