-
Notifications
You must be signed in to change notification settings - Fork 87
Conversation
I'm not saying "THIS IS WHAT IS HAPPENING". This is just my proposal, I wanted to make something to compare to the original PR. |
Well, it would be a major version bump and it's good that it requires action. Those that previously got away with bad keys (and they are bad, they have no meaning and are not tied to the element's identity) would be forced to fix them, improving performance and debugging (maybe). I just never liked the fact that I was doing something behind the users back, sneakily filling in a gap you're meant to do yourself. I'm not sure what you mean by "we already know what the keys are going to be" though. Is it really that bad to add keys to multiple children, just like you'd have to in regular React anyway? I think not. I think it keeps the faux DOM inline with how React actually works instead of diverging from it. |
You don't need a key for single children now.
Added the optimisation such that: <div>{[child]}</div> Is now: <div>{child}</div> Which does not require a key. Cleaned up that recursion call in |
@Olical I do understand your intent and I admit that it is easy to add keys for code that you write yourself. But what about code that you don't write yourself? Even the simplest things like d3.svg.axis will give you React key warnings, as they produce elements like this: <g transform="translate(0,420)" class="x axis">
<g transform="translate(0,0)" style="opacity: 1;" class="tick">
<line x2="0" y2="-420"></line>
<text x="0" y="3" style="text-anchor: middle;" dy=".71em">2000</text>
</g>
<g transform="translate(86.76724137931035,0)" style="opacity: 1;" class="tick">
<line x2="0" y2="-420"></line>
<text x="0" y="3" style="text-anchor: middle;" dy=".71em">2001</text>
</g>
<g transform="translate(173.29741379310346,0)" style="opacity: 1;" class="tick">
<line x2="0" y2="-420"></line>
<text x="0" y="3" style="text-anchor: middle;" dy=".71em">2002</text>
</g>
<path d="M0,-420V0H880V-420" class="domain"></path>
</g> How would we deal with that? |
@FunkMonkey Agreed. It's not the same to ask the user for "filling in the gaps" in faux-dom, like React can.
@Olical I mean, that faux-dom Elements are mutable. We are keeping them around and mutating them, eventually calling |
Ah, there's an interesting difference in our use case then. I'm essentially I wouldn't recommend keeping the element around outside of the render call, On 21 September 2016 at 14:10, Phil Pluckthun notifications@github.com
|
@Olical What about your animate-d3-with-mixin example? It will throw key warnings due to It is not really about keeping the the faux elements around or recreating them each time in I personally like function render() {
const fauxXAxis= Faux.createElement( 'g' );
d3.select( fauxXAxis )
.call( d3.svg.axis() ); // no control over keys of ticks
const fauxYAxis= Faux.createElement( 'g' );
d3.select( fauxYAxis )
.call( d3.svg.axis() );
const circles = [ 100, 200 ].map( ( val, i ) => <circle key={i} r="10" cx={val} cy={val} />
const circleGroup = <g key="circles">{circles}</g>
return (
<svg height="300" width="300">
{ [ fauxXaxis.toReact( 'x' ), fauxYaxis.toReact( 'y' ), circleGroup ] }
</svg>
);
} This simplified example is the main reason I use |
@Olical My PR also doesn't abolish creating faux-dom elements on the fly. It "falls back" to the element order in that case. It also doesn't prevent the user from using |
Ah, I see what you mean with those deep structures now. I'll go over your PR again then, there's a couple of changes I made here that I would like to see in yours, only small things. Maybe I'll merge yours and just do it myself, namely the function I refactored out for the recursion. |
Closing this because I now realise automatic keys are required. I don't think global automatic keys are the way though, so a middle ground would be awesome. The |
My ideal scenario, an alternate approach to #67 and #73. May not be to everyone's taste.
Also, the scenario where you need to add a key even with just one child can probably be avoided some other way. I will have a think about that one. I just wanted to show that it's pretty easy to just add keys where React tells you to.
Should yield more efficient applications too, right now I would imagine many people using this are seeing far higher CPU usage because they don't understand the key system. Which is technically undocumented!