Description
Consider this:
render: function () {
return <div>{arr.map(this.renderItem)}</div>;
}
Usually, key
is respected in this case and elements don't get unmounted and remounted unnecessarily if their key
s match between subsequent render
calls.
However, if all elements but one are removed, React 0.10.0 for some reason doesn't realize it's the same component (the key
hasn't changed) and forces its DOM node to update.
I tried setting a breakpoint inside shouldUpdateReactComponent
and _updateChildren
to debug the issue and it looks like prevComponentInstance
is null
because its name in nextChildren
and prevChildren
is slightly different (in one case it includes leading 0:
, in the other it doesn't).
Anyway, the workaround for me was, curiously, not returning an array when there is just one item, and rendering it as is. In this case, React was able to understand it's the same component, and didn't force an unnecessary re-render.
I'm sorry for not providing a workable fiddle or something—jsFiddle hosts an old version of React, and it's 8am where I live so I should go to sleep. This should be fairly simple to reproduce, unless it's already fixed.