yysun/apprun

should __componentCache be global?

maparent opened this issue · 0 comments

In this line, we see that recursive component creation passes the ancestor down in the parent variable.

vdom.children = vdom.children.map(child => createComponent(child, parent, _idx));

(vs vdom.children = vdom.children.map(child => createComponent(child, vdom, _idx));)
This means that, in this line:
let component = parent.__componentCache[key];

we're using the ancestor's cache if rendering the ancestor, and the parent's cache if rendering the parent. I have observed cache miss and recreation of components for that reason. (sometimes with missing sub-components, but that last part could be a problem on my side.)
I tried using vdom and ran into other issues with missing elements. I'm also not sure about the intent here.
The issue with a global cache might be ID collision; a local cache would fail on a drag and drop, but that's a lesser concern.
Either way, I think it would be good to make sure it is used consistently.