bigskysoftware / idiomorph

A DOM-merging algorithm
BSD 2-Clause "Simplified" License
631 stars 31 forks source link

Can't handle document fragments #53

Open mihaiav opened 2 months ago

mihaiav commented 2 months ago

I'm trying to morph a document fragment but it seems that for some reasons this fails. I also wrote a test. Am I doing something wrong. The test represents the way my "framework" works(i.e. using document fragments to encapsulate one or more nodes)

2) Core morphing tests can handle document fragments: TypeError: Cannot read properties of null (reading 'replaceChild') at morphOldNodeTo (file:///Users/x/go/src/github.com/AVML/idiomorph/src/idiomorph.js:135:39) at morphNormalizedContent (file:///Users/x/go/src/github.com/AVML/idiomorph/src/idiomorph.js:91:35) at Object.morph (file:///Users/x/go/src/github.com/AVML/idiomorph/src/idiomorph.js:53:20) at Context. (core.js:465:19)

// test code https://github.com/bigskysoftware/idiomorph/pull/54


   it('can handle document fragments', function()
     {
         let tpl = document.createElement("template");
         tpl.innerHTML = "<div><button>Foo</button><div>";
         let initial = document.adoptNode(tpl.content);
         let initialFirstChild = initial.firstChild;

         tpl = document.createElement("template");
         tpl.innerHTML = "<p>x</p><p>y</p>"
         let replaceWith =  document.adoptNode(tpl.content);
         Idiomorph.morph(initialFirstChild, replaceWith, {});
         initial.outerHTML.should.equal(`<p>x</p><p>y</p>`);
     });