Matt-Esch / virtual-dom

A Virtual DOM and diffing algorithm
MIT License
11.66k stars 779 forks source link

Patch does nothing #435

Closed are closed 3 years ago

are commented 7 years ago

I have no idea what I'm doing wrong, but it seems like patch is doing completely nothing (even with populated patches). How is this possible? No error thrown, just silently does nothing.

    let _rootElement = document.querySelector(el.value)

    let rootTree = h('div')
    let rootNode = createElement(rootTree)

    _rootElement.appendChild(rootNode)

    let updateFn = () => {
      let vElement = c.execute().value // this returns new VNode

      let patches = diff(rootTree, vElement) // this returns an object with few patches
      rootNode = patch(rootNode, patches) // THIS does nothing

      rootTree = vElement
    }
are commented 7 years ago

I think this happens, when VNode returned by the c.execute().value has children added after using h. May it be the reason?

gryphonmyers commented 7 years ago

Did you ever figure this out? I'm experiencing something similar.

are commented 7 years ago

I think you cannot manipulate the vnodes after creating them, so check if you don't append children somewhere in your code.

gryphonmyers commented 7 years ago

You're absolutely right. There was a place in my code where I was making VNodes then appending new children to them.

ghost commented 5 years ago

@gryphonmyers Close the issue.

gryphonmyers commented 5 years ago

Would if I could!