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

Incorrect Children Position #132

Open
kienhg96 opened this issue Jul 7, 2018 · 1 comment
Open

Incorrect Children Position #132

kienhg96 opened this issue Jul 7, 2018 · 1 comment

Comments

@kienhg96
Copy link

kienhg96 commented Jul 7, 2018

React Masonry sometimes renders incorrect children position (overlap).

Image: https://ibb.co/mduYe8

After I wrap this.masonry.layout() by setTimeout inside performLayout method, it renders correctly.

performLayout: function() {
    var diff = this.diffDomChildren();
    var reloadItems = diff.forceItemReload || diff.moved.length > 0;

    // Would never be true. (see comments of 'diffDomChildren' about 'removed')
    if (diff.removed.length > 0) {
      if (this.props.enableResizableChildren) {
        diff.removed.forEach(this.erd.removeAllListeners, this.erd);
      }
      this.masonry.remove(diff.removed);
      reloadItems = true;
    }

    if (diff.appended.length > 0) {
      this.masonry.appended(diff.appended);

      if (diff.prepended.length === 0) {
        reloadItems = true;
      }

      if (this.props.enableResizableChildren) {
        diff.appended.forEach(this.listenToElementResize, this);
      }
    }

    if (diff.prepended.length > 0) {
      this.masonry.prepended(diff.prepended);

      if (this.props.enableResizableChildren) {
        diff.prepended.forEach(this.listenToElementResize, this);
      }
    }

    if (reloadItems) {
      this.masonry.reloadItems();
    }
// ===> HERE
    setTimeout(() => {
      this.masonry.layout();
    });
// ===
  },
@phthhieu
Copy link

Hi @eiriklv, this happens to my project too, but just unpredictably, do you have any suggestions to fix this?

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