question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Browser crashs when re-rendering Masonry childrens

See original GitHub issue

When updating the Masonry items (childrens), the browser crash.

You can view it live here

Reproduce: Switch between tabs (woman and man), or select/unselect one of the carousel items (the movies). The Masonry, for some reason breaks and the browser crashs.

This is the code that renders the Masonry:

import Masonry from 'react-masonry-component';

// ...

const posters = this.props.content.map((item, index) => {
      return (
        <OutfitPoster
          key={index}
          className={[styles.productItem, stylesMasonry.item].join(' ')}
          title={item.content_title}
          description={item.product.name}
          imageSrc={item.content.thumbnail}
          shopLink={item.product.link}
        />
      )
});

return (
   <Masonry className={[styles.products, stylesMasonry.masonry].join(' ')}
        updateOnEachImageLoad
      >
          {posters}
      </Masonry>
    );
)

This this.props.content changes each time I filter it by selecting a tab or movie.

Thanks!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
jerryslawcommented, Jul 6, 2017

Hi. I have similar issue. onLayoutComplete is calling several times, I don’t know why. When I use @sandrina-p solution, it fires only once, but - I want to change my redux state when layout is completed, so I’m calling some function from props, and then… My call stack is exceeded, onLayoutComplete is in infinite call loop.

My code is:

import React from 'react';
import PropTypes from 'prop-types';
import Masonry from 'react-masonry-component';
import { connect } from 'react-redux';
import compose from 'lodash/fp/compose';

import FetchContainer from 'containers/Fetch';
import { galleryFetch, openGalleryPreview } from 'store/actions';

import './Gallery.scss';

const masonryOptions = {
  itemSelector: '.gallery__item',
  columnWidth: 300
};

class GalleryComponent extends React.Component {

  static propTypes = {
    data: PropTypes.arrayOf(PropTypes.object),
    openPreview: PropTypes.func,
    changeLayoutStatus: PropTypes.func
  };

  static defaultProps = {
    data: []
  };

  componentDidMount() {
    this.props.changeLayoutStatus(false);
  }

  layoutComplete = () => {
    this.props.changeLayoutStatus(true);
  };

  render() {
    const { data: images, openPreview, changeLayoutStatus } = this.props;

    return (
      <div className="gallery">
        <div className="gallery__images">
          <Masonry
            key={new Date().getTime()}
            className="gallery__masonry"
            options={masonryOptions}
            onLayoutComplete={this.layoutComplete}
          >
            {
              images.map((image, i) => (
                <div key={i} className="gallery__item">
                  <img src={image.url} alt={image.name} onClick={() => openPreview(images.indexOf(image))} />
                </div>
              ))
            }
          </Masonry>
        </div>
      </div>
    );
  }
}

const mapDispatchToProps = {
  changeLayoutStatus: changeGalleryLayoutStatus,
  openPreview: openGalleryPreview
};

export default compose(
  FetchContainer(galleryFetch, 'gallery'),
  connect(null, mapDispatchToProps)
)(GalleryComponent);

Difference is that () => console.log('called') is calling only once (as expected), but my function is calling infinitely.

PS. My GalleryComponent is not re-rendering after each call of changeLayoutStatus

0reactions
aframcommented, Apr 16, 2018

@jerryslaw I know this is a very old ticket. Are you in a position to try the latest version and see how it works for you. Does it solve your problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React js crashes after re render with different child elements ...
This component renders fine once. After changing propery, react js try re render and crash with error (Uncaught TypeError: Cannot read property ......
Read more >
Rendering large lists with React Virtualized - LogRocket Blog
First, you'll see the problems with rendering a huge data set. Then, you'll learn how React Virtualized solves those problems and how to ......
Read more >
PRMan 15.0 Release Notes - Pixar's RenderMan
A bug with baked procedurals that could lead to crashes in rerendering mode has been fixed. A bug in the re-rendering mode of...
Read more >
Release Notes (3.5) - Cinema 4D User Guide - Maxon
[C4D] Addressed a crash issue in certain configurations of the Multi-Shader ... [RenderView] Fixed issue where view is re-centered when using Render Region ......
Read more >
Render Large Lists Efficiently with React Virtualized - CopyCat Blog
For example, if you're rendering a list of items using List that may be ... These problems could cause the UI to come...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found