Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue with integer keys + heterogeneous siblings #38

Closed
steven88888 opened this issue Feb 4, 2016 · 4 comments
Closed

Possible issue with integer keys + heterogeneous siblings #38

steven88888 opened this issue Feb 4, 2016 · 4 comments

Comments

@steven88888
Copy link

One component named Todo has a render function as following. It will ganerate one Todo list with js codes compiled by React Templates. 2 problems will happen:

  1. If todo.key is integer (which can be zero), add operation would be not work well.
  2. After delete one todo array element of state, UI element can not be removed correspondingly.

I am a fresher of Preact. Maybe they are related to preact/src/vdom/build.js, please check and confirm. Thanks.

<div> 
    <div key="{todo.key}" class="todo-item" rt-repeat="todo in this.state.todos">        
        <img src="src/assets/delete.png"
             onClick="()=>this.remove(todo)"
             title="Remove Todo" />
        <input type="checkbox" checked="{todo.done}" onChange="()=>this.toggleChecked(todoIndex)"/>
        <span rt-class="{done: todo.done}">{todo.value}</span>
    </div>  
    <input key="myinput" class="new-todo" placeholder="What needs to be done?" type="text"
           value="{this.state.edited}"
           onKeyDown="{(e) => this.inputKeyDown(e)}"
           onInput="{this.linkState('edited')}"
           autoFocus="{true}"/>
    <button onClick="()=>this.add()">Add</button><br/>
    <button onClick="()=>this.clearDone()">Clear done</button>
</div>
@steven88888
Copy link
Author

If i remove the attribute key of <div>, the 2nd problem will disappear.

@developit
Copy link
Member

Hi Steven,

I've never used React Templates, and honestly I wouldn't recommend an approach like that in the first place. Here's a working example of what you wrote, without any of the templating stuff:

https://jsfiddle.net/developit/hq33t3vm/

That being said, it looks like there is an issue with integer keys, which I will certainly look into!

@developit developit changed the title it can not keep consistent updating between State and UI ( rendering ) Possible issue with integer keys + heterogeneous siblings Feb 4, 2016
@steven88888
Copy link
Author

Hi Jason,
thanks for your answer.

@developit
Copy link
Member

Fixed in 3.4.0!

marvinhagemeister added a commit that referenced this issue Mar 2, 2019
Fix regressions introduced with Fragments PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants