intercellular / cell

A self-driving web app framework
https://www.celljs.org
MIT License
1.5k stars 94 forks source link

Uncaught TypeError: Cannot read property '$type' of undefined (in Membrane.build) #27

Closed devsnek closed 7 years ago

devsnek commented 7 years ago

Something causes Gene.diff to create a diff with an undefined item, which causes errors when building a new Membrane because reading $type of undefined.

The fix I specify below is probably not the right thing to do because of the way the error is triggered (see below). The addition of the $update function and the root cell being body are what specifically cause this error to happen.

Code to repro:

window.app = {
  $cell: true,
  $type: 'body',
  $components: [
    { $type: 'div', $update: function() {} },
  ],
};

My current fix:

diff --git a/cell.js b/cell.js
index b4d1e3b..ee02462 100644
--- a/cell.js
+++ b/cell.js
@@ -105,7 +105,7 @@
       var plus = _new.map(function(item, index) {
         return { item: item, index: index }
       }).filter(function(item, index) {
-        return new_common.indexOf(index) === -1
+        return item.item && new_common.indexOf(index) === -1
       })
       return { "-" : minus, "+": plus }
     }
gliechtenstein commented 7 years ago

Hi, I tried the code above but couldn't replicate the error. Could you share a full HTML? That would be helpful for debugging.

gliechtenstein commented 7 years ago

Actually, i've been taking a possibly related problem this morning, which occurs when injecting into an existing element (such as body). This was the fix, I'm not sure if this would help fix your case, but please do try out the latest update from the develop branch and see if that fixes the problem.

thank you!

devsnek commented 7 years ago

this appears to have fixed it, closing for now