Skip to content

DOM updates not minimal when moving last child to first place #1422

Closed
@steadicat

Description

@steadicat

When a rerender requires the last child to be moved to first place, the update to the DOM is not minimal. Instead of removing the child in question and re-inserting it, all the other children are removed and re-added instead.

This is bad for two reasons:

  1. It is unnecessary churn on the DOM, slowing things down. If any of the children is or contains a video element, the video will reset.
  2. Using keys to shuffle children around is pretty common when implementing an infinite scroll in React with DOM element reuse. This should work.

Here's a screencast showing how the DOM is changed while I scroll. Notice how when I scroll down the first element is correctly removed from the top and inserted at the bottom. When I scroll back up, instead of moving the last element, React moves the other four.

https://dl.dropboxusercontent.com/u/140702/ReactDomOperations.mov

I'm using React 0.9.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions