Closed
Description
The current state of implicit keys in React, psuedo-JSX:
1. <div .0><span .0.0 /></div>
2. <div .0>[<span .0.0 />]</div> -- GOOD reconciles .0.0
1. <div .0><span .0.0 /></div>
2. <div .0>[<span .0.0 /><span .0.1 />]</div> -- GOOD reconciles .0.0
1. <div .0><span .0.0 /><span .0.1 /></div>
2. <div .0>[<span .0.0:0 />]<span .0.1 /></div> -- BAD destroys .0.0
1. <div .0>[<span .0.0 />]</div>
2. <div .0>[[<span .0.0:0 />]]</div> -- BAD destroys .0.0
I propose Array/Set should ignore tailing sub-array indices with value 0 and if the root is an only child then it has index 0 (this is currently the case, except it's broken for objects):
.0.0 => .0.0
.0.0:0:1:0:0 => .0.0:0:1
.0.0:0:1:0:0:1:0:0 => .0.0:0:1:0:0:1
The first ReactNode in every Array now reconciles from and to any depth. If we want to improve Maps to reconcile in the same way then all previous indices should be discarded when a Map is encountered (possibly discarding the entire "computed name so far" even).
Pseudo-JSX showing how the new indices would be computed ([...]
is discarded), all the examples at the top now reconcile correctly.
<div .0>
[
[
<span .0.0[:0:0] />
[
<span .0.0:0:1[:0] />
[
[
<span .0.0:0:1:1[:0:0] />
<span .0.0:0:1:1:0:1 />
]
]
<span .0.0:0:2 />
]
<span .0.0:1 />
]
<span .0.1 />
</div>
cc @sebmarkbage