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

Render activity list items fully first when they enter viewport #2417

Merged
merged 1 commit into from
Dec 8, 2024

Conversation

awarn
Copy link
Collaborator

@awarn awarn commented Dec 7, 2024

Description

Wraps the items of activity list in an IntersectionObserver component that waits for them to be inside the viewport before rendering them (which defers loading until then as well).

Displays a 'pending' list item to look a little neater on loading flash, and also take about roughly the same space as the actual items would.

Related issues

Resolves #2396

@awarn
Copy link
Collaborator Author

awarn commented Dec 7, 2024

I should really clean this up a little before merge, the new component can be its own file. And also we maybe should discuss an alternative: Extending the actual list items (CallAssignmentListItem, etc) with logic to wait with loading their data but render their own 'pending' state rather than relying on stopping their render as I did here. My current version was just quicker than modifying them all. Tell me what you prefer, I see some pros and cons with both.

@richardolsson
Copy link
Member

This is an impressive solution! There have been plans to make some major changes to the pages where these lists live, so I don't think it is necessary to make this perfect. I'll review properly, but just wanted to stop in real quick and let you know that you should feel no pressure to clean this up!

Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

I have reviewed the code and I've tried the build. I confirmed that not all data is loaded on first draw, but more data is loaded as the user scrolls.

I'm going to approve it as is because I'm eager to get this merged. But please note my question about garbage collection below and if you believe that something needs to be done let me know and we can create a separate issue for that. 😊

return;
}

const observer = new IntersectionObserver((entries) => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm so glad you introduced this solution. I was not aware of IntersectionObserver (like I was with ResizeObserver and observers in general) so I had to look it up, but it's covered by all browsers that we care about so I think it's the ultimate solution for us.

});
});

observer.observe(boxRef.current);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to unobserve or destroy the observer when the component unmounts, or will that be handled automatically by the browser when React removes the element from the DOM?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From what I can find in discussions the intent is for garbage collection to deal with it if observer is no longer observing any elements (using weak references):
w3c/csswg-drafts#6397

@richardolsson richardolsson merged commit 0e8be00 into zetkin:main Dec 8, 2024
6 checks passed
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.

Activity archive loads everything at once (and prevents further navigation)
2 participants