Problem/Motivation
The Views Infinite Scroll module overrides any View attributes and classes that are possibly set by core or other modules specifically for Masonry for this matter. This is the code that causes the issue:
$vars['rows']['#theme_wrappers']['container'] = [
'#attributes' => [
'data-drupal-views-infinite-scroll-content-wrapper' => TRUE,
'class' => [
'views-infinite-scroll-content-wrapper',
'clearfix',
],
],
];
Here is a screenshot of using Xdebug to see the values that exist and how they will change:

Steps to reproduce
- Install latest Drupal 8 version - currently at 8.9.2
- Download and enable the following modules: Views Infinite Scroll(8.x-1.7), Masonry API(8.x-1.1) and Masonry Views(8.x-1.1)
- Create a View that will use Masonry as the Format and Infinite Scroll as the Pager. Make sure there are content to output inside the View.
- Go to the page and notice that Masonry won't work but Infinite Scroll works when you scroll down.
- Check the markup using inspect element specifically the DIV directly after the .view-content DIV wrapper of the View
- Notice that will only have the attributes an classes of Views Infinite Scroll. This might also not be the case if the module order could be re-ordered where Masonry runs later than Views Infinite Scroll but the code still isn't dynamic to adjust if there are existing data in the array
Proposed resolution
Refactor the Views Infinite Scroll code to add its attributes and classes to the `$vars['rows']['#theme_wrappers']['container'] ` array rather than replacing its contents, if there are any.
Comments
Comment #2
leolandotan commentedHere is a patch that fixes the said issue.
This is the expected output where the attributes and classes from Views Infinity Scroll and Masonry are all present:

Hope everything is in order.
Thank you!
Comment #3
leolandotan commentedComment #4
leolandotan commentedComment #5
neslee canil pinto@leolando.tan its not the right way to declare rows attributes in 3 seperate lines.
Comment #6
olivier.br commented@Neslee Cani Pinto, i don't really see how you could do better without overwritting existing attributes. Maybe you could give us a tip ?
Comment #7
dom. commentedMasonry modules suite maintainer here.
This module overrides other modules and themes #attributes as explained in issue description. Some other modules too, just like this one, require some #attributes on the rows container.
Therefore the compatibility with 'Masonry' is broken by this module.
I would have offered exactly the same patch as #2 since that is how I have done in masonry module. Therefore, I am marking this issue as RTBC for this reason. Also bumping to 'major' since this actually prevents the usage of masonry in conjunction with this module.
Comment #9
neslee canil pintoCommitted to dev branch. Thanks.