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

WIP: Moving off of react-virtualized to react-window #467

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wuweiweiwu
Copy link
Member

@wuweiweiwu wuweiweiwu commented Mar 21, 2019

closes: #425

dependent on frontend-collective-react-dnd-scrollzone supporting refs to the inner component frontend-collective/frontend-collective-react-dnd-scrollzone#7

currently running into some invariant issues idk. but stuff mostly works.

  • fix search and scrollToItem
  • fix invariant issues when dragging

@dolezel not really sure what the invariant issue is. It happens when you drag to to the left of the root. Not as familiar with react-dnd :\

Screen Shot 2019-03-21 at 2 01 20 AM

@wuweiweiwu wuweiweiwu changed the title Moving off of react-virtualized to react-window WIP: Moving off of react-virtualized to react-window Mar 21, 2019
@wuweiweiwu wuweiweiwu requested a review from dolezel March 21, 2019 06:00
@dolezel
Copy link
Collaborator

dolezel commented Mar 22, 2019

I will try to look on it, but not sure when I will have time...

rowRenderer={({ index, style: rowStyle }) =>
{...reactVirtualizedListProps}
>
{({ index, style: rowStyle }) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the issue. It creates new function every render and so every row is mounted and unmounted. You should extract it to extra function and give here only reference to that function so it remains always same.

E.g.

this._render = this._render .bind(this); // in constructor

...

_render({ index, style: rowStyle }) {
    const {
      getNodeKey,
    } = mergeTheme(this.props);
    const {
      searchMatches,
      draggedNode,
      draggedDepth,
      draggedMinimumTreeIndex,
      instanceProps,
    } = this.state;

    const treeData = this.state.draggingTreeData || instanceProps.treeData;

    let rows;
    let swapFrom = null;
    let swapLength = null;
    if (draggedNode && draggedMinimumTreeIndex !== null) {
      const addedResult = memoizedInsertNode({
        treeData,
        newNode: draggedNode,
        depth: draggedDepth,
        minimumTreeIndex: draggedMinimumTreeIndex,
        expandParent: true,
        getNodeKey,
      });

      const swapTo = draggedMinimumTreeIndex;
      swapFrom = addedResult.treeIndex;
      swapLength = 1 + memoizedGetDescendantCount({ node: draggedNode });
      rows = slideRows(
        this.getRows(addedResult.treeData),
        swapFrom,
        swapTo,
        swapLength
      );
    } else {
      rows = this.getRows(treeData);
    }
    const matchKeys = {};
    searchMatches.forEach(({ path }, i) => {
      matchKeys[path[path.length - 1]] = i;
    });
    return this.renderRow(rows[index], {
      listIndex: index,
      style: rowStyle,
      getPrevRow: () => rows[index - 1] || null,
      matchKeys,
      swapFrom,
      swapDepth: draggedDepth,
      swapLength,
    })
  }

...

{this._render} // here

Should be good to refactor this so there is not much extra computations...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I would also consider it bug in react-dnd, but it is a question if it gets addressed anytime soon ...
https://github.com/react-dnd/react-dnd/search?q=Expected+to+find+a+valid+target&type=Issues

}}
height={height}
style={innerStyle}
rowCount={rows.length}
estimatedRowSize={
itemCount={rows.length}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add
itemKey={(index) => getNodeKey(rows[index])}

@themausam
Copy link

I have this similar error when dragging from one tree to another. It occurs after dropping on 2nd tree and does not happen on every single node but happens most of the time.

Capture

@wuweiweiwu wuweiweiwu self-assigned this May 3, 2019
@mx2323
Copy link

mx2323 commented Jun 13, 2019

had the same problem, take a look at this issue -
react-dnd/react-dnd#1368

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

Successfully merging this pull request may close these issues.

Move to a smaller list virtualization library
4 participants