jorgebucaran / superfine

Absolutely minimal view layer for building web interfaces
https://git.io/super
MIT License
1.56k stars 78 forks source link

Potential bug when recycling nested elements #183

Closed whaaaley closed 3 years ago

whaaaley commented 3 years ago

I apologize in advance if this is not supported or if I'm just doing something wrong, but I'm getting some inconsistent behavior when toggling some children in my view. When using conditionals in nested element's children, upon recycling, (initial renders are fine), I get a few different errors.

Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'. and Failed to execute 'insertBefore' on 'Node': parameter 2 is not of type 'Node'. and Cannot read property 'key' of undefined

h('div', {}, [
  state.foo === false && h('h1', {}, [text('hello')])
])

I have a repro here based on the todo app example in the read me. If you comment/uncomment some of the lines you can see the two different errors in the dev tools. https://codepen.io/dustindowell/pen/ExNYbQK?editors=1010

In the meantime I'm doing stuff like this as a work around. If this was the "correct" way of doing things, I'm down for it, but some consistency between initial render and recycles might be worth looking into.


const ErrorComponent = props => {
  if (props.show === true) {
    return h('div', {}, [text(props.message)])
  }

  return h('div', { hidden: true }, []) // node placeholder
}
jorgebucaran commented 3 years ago

Thanks for the bug report. Your pen now works with 8.1.0. 🎉✨