ivanceras / hackernews-sauron

A fast, resilient, isomorphic hacker news clone in ~1k lines of rust.
MIT License
114 stars 7 forks source link

Client crash #1

Closed ctsrc closed 2 years ago

ctsrc commented 3 years ago

Hi, when I build and run this project and then load http://localhost:3000 and click on "best" in the orange top bar of the site and then click on "top" in the same orange top bar, the page stops working. I get output in the console showing that this is due to a crash.

The full output is quite long so I am initially posting only the beginning of the two messages that show up in the console:

client.js:321 panicked at 'must have a parent node, tag: Some("ol"), path: TreePath { node_idx: 110, path: [0, 2, 0, 0, 4] }, for patch: Element(
    Element {
        namespace: None,
        tag: "li",
        attrs: [
            Attribute {
                namespace: None,
                name: "key",
                value: [
                    I64(
                        28199994,
                    ),
                ],
            },
        ],
[...]

and

client_bg.wasm:0x9a362 Uncaught RuntimeError: unreachable
    at __rust_start_panic (client_bg.wasm:0x9a362)
    at rust_panic (client_bg.wasm:0x98546)
    at std::panicking::rust_panic_with_hook::h2d9079427a2d996a (client_bg.wasm:0x8a5f0)
    at std::panicking::begin_panic_handler::{{closure}}::h4e49f350d9f4de36 (client_bg.wasm:0x8fd5f)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h91e711607d91be52 (client_bg.wasm:0x97dfc)
    at rust_begin_unwind (client_bg.wasm:0x97074)
    at std::panicking::begin_panic_fmt::h7a3482363d68bbca (client_bg.wasm:0x97b8c)
    at sauron_core::dom::apply_patches::apply_patch_to_node::{{closure}}::h75823b077a8bf1f0 (client_bg.wasm:0x90153)
    at sauron_core::dom::apply_patches::patch::hbbaec4fc219f9cfc (client_bg.wasm:0x32ca2)
    at sauron_core::dom::dom_updater::DomUpdater<MSG>::update_dom::h1ec3d272cce49647 (client_bg.wasm:0x5c501)
$__rust_start_panic @ client_bg.wasm:0x9a362
$rust_panic @ client_bg.wasm:0x98546
[...]

The browser I am using is Brave Version 1.28.105, which is based on Chromium: 92.0.4515.131 (Official Build) (arm64). Running on a MacBook Pro M1 with macOS Big Sur Version 11.5.2.

ivanceras commented 3 years ago

Thanks for reporting @ctsrc , I'll look into it.

ivanceras commented 3 years ago

I have replicated the issue and it has to do with the dom-diffing optimization when the keyed elements are changed in their order.

Explanation:

Each item in hacker news has a unique id, and is used as key as in keyed-element, The top and best stories will mostly like have stories that are present in both listing, and they only differ in arrangement.

The algorithm that handles this must keep track of which element has matched or has passed that could have matched. If it has passed the element that could have matched, should not be matched and will therefore be deleted.

For the time-being this fixed by not using a keyed element on the stories, until the dom-diffing code is modified to handle this cased.

ivanceras commented 2 years ago

This has been fixed in the released of sauron 0.49.2 and mt-dom 0.19, which is the version used in the repo.