hexops / vecty

Vecty lets you build responsive and dynamic web frontends in Go using WebAssembly, competing with modern web frameworks like React & VueJS.
BSD 3-Clause "New" or "Revised" License
2.79k stars 144 forks source link

removeChild crashes if parent node is nil #286

Closed VinceJnz closed 2 years ago

VinceJnz commented 2 years ago

if removeChild is called with a child node that has no parent in the DOM it will crash.

https://github.com/hexops/vecty/blob/2abc3fbe89ef72f3767236869a48635516765135/dom.go#L641-L656

The following Line https://github.com/hexops/vecty/blob/2abc3fbe89ef72f3767236869a48635516765135/dom.go#L655 could be replaced with something like the following...

    parentNode := child.node.Get("parentNode") //Added this because if the child has had the parentNode removed this will crash
    if parentNode == nil {
        log.Println("vecty: parentNode is nil") //The error could be logged??
        //panic("vecty: DOM parent node is nil") // or it could trigger a panic??
        return // or just return??
    }
    parentNode.Call("removeChild", child.node)

This is a similar response to the child.node being nil.

VinceJnz commented 2 years ago

After spending a bit more time on using vecty and understanding some better ways to create views this is not the right approach.