yelouafi / petit-dom

minimalist virtual dom library
MIT License
501 stars 36 forks source link

Bug - Can't handle nodes with with empty strings or strings with only spaces. #26

Closed cjh9 closed 5 years ago

cjh9 commented 5 years ago

Hi @yelouafi the example I sent before doesn't work with strings with spaces also...

<body>
<script type="module">
import {h, patch, mount} from 'https://unpkg.com/petit-dom?module'

const oldVnode =  h("div", {}, [
  h("div", {}, [
    h("h1", {}, ["Text"]),
    h("div", {}, ["Text"]),
    h("div", {}, ["Text"]),
    h("div", {}, ["Text"]),
    h("div", {}, ["Text"])
  ]),
  h("div", {}, [
    h("div", {}, [
      "   ",
      h("div", {}, ["Text"]),
      h("pre", {}, [h("code", {}, [h("span", {}, ["Text"]), " "])]),
      h("div", {}, []),
      h("div", {}, []),
      " "
    ])
  ]),
  h("p", {}, ["Text"]),
  " ",
  h("pre", {}, [h("code", {}, ["Text"])]),
  h("p", {}, ["Text"])
]);

const newVnode = h("div", {}, [
  h("div", {}, [
    h("h1", {}, ["Text"]),
    h("div", {}, ["Text"]),
    h("div", {}, ["Text"]),
    h("div", {}, ["Text"]),
    h("div", {}, ["Text"])
  ]),
  h("div", {}, [
    h("div", {}, [
      " ",
      h("div", {}, ["Text"]),
      h("p", {}, ["Text"]),
      h("div", {}, []),
      h("div", {}, []),
      " "
    ])
  ]),
  h("pre", {}, [h("code", {}, [h("span", {}, ["Text"]), " "])]),
  h("p", {}, ["Text"]),
  " ",
  h("pre", {}, [h("code", {}, [h("span", {}, ["Text"]), " "])])
]);

document.body.appendChild(mount(oldVnode))
patch(newVnode, oldVnode)
</script>
</body>
yelouafi commented 5 years ago

cf v0.2.3