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

Reader: enable pagination controls for Recent Feed #97674

Merged
merged 5 commits into from
Jan 10, 2025

Conversation

holdercp
Copy link
Contributor

@holdercp holdercp commented Dec 19, 2024

Fixes Automattic/loop#238
Fixes Automattic/loop#247

Proposed Changes

"Pads" the stream item results so the correct number of items are present for the DataViews pagination to work correctly.

Screen.Recording.2025-01-09.at.4.43.01.PM.mov

There were two solutions I explored in fixing this issue:

  1. "Padding" the state with empty items so DataViews had the correct number of items for pagination to work correctly.
  2. Requesting enough items from the API so DataViews had the correct number of items for pagination to work correctly.

See "Why are these changes being made" for an explanation of the issue.

I implemented approach 1 because it provided the best UX. The major downside is the additional code/types to handle a stream including "padding" items.

Why are these changes being made?

  • The DataViews component has its own pagination implementation. In order for this pagination to work correctly, however, it needs all the items for a given page and page size passed to it as a prop.
    • For example, if page 4 is selected in the DataViews component with a page size of 10, DataViews needs its items prop to have 40 or more items in it for the pagination logic to work correctly.
  • Our current way of requesting pages from the /read/streams/following endpoint would request a single page at a time of a given size and add those results to the store.
  • This causes an issue with the DataViews pagination highlighted in this slack convo: p1733503754426959-slack-C03NLNTPZ2T where if a user selected pages out of order then the DataViews pagination would break.
    • As an example, if a user selects page 4 after initial load the endpoint would return page 4 of the results and those items would be stored in the store. With a page size of 10, this would mean that the store had 20 items in it: page 1 (from initial load) and page 4.
    • Those 20 items would be passed to DataViews and when it tried to render page 4 with a page size of 10 with only 20 items, it would break.

Testing Instructions

  • Navigate to the Reader (/read)
  • Use the pagination controls for different feeds
  • Make sure the items are in the correct chronological order
  • Generally try to break the pagination

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@holdercp holdercp self-assigned this Dec 19, 2024
@holdercp holdercp requested a review from a team as a code owner December 19, 2024 21:35
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 19, 2024
@matticbot
Copy link
Contributor

matticbot commented Dec 19, 2024

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~246 bytes added 📈 [gzipped])

name                             parsed_size           gzip_size
reader                                +676 B  (+0.0%)     +246 B  (+0.1%)
plugins                               +384 B  (+0.0%)     +152 B  (+0.0%)
jetpack-cloud-plugin-management       +384 B  (+0.0%)     +152 B  (+0.0%)
home                                  +384 B  (+0.0%)     +152 B  (+0.0%)
write-flow                            +316 B  (+0.0%)     +136 B  (+0.0%)
site-blocks                           +316 B  (+0.0%)     +136 B  (+0.1%)
link-in-bio-tld-flow                  +316 B  (+0.0%)     +136 B  (+0.0%)
build-flow                            +316 B  (+0.0%)     +136 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~136 bytes added 📈 [gzipped])

name                                                     parsed_size           gzip_size
async-load-design-blocks                                      +316 B  (+0.0%)     +136 B  (+0.0%)
async-load-calypso-components-web-preview-component           +316 B  (+0.1%)     +136 B  (+0.1%)
async-load-calypso-blocks-support-article-dialog-dialog       +316 B  (+0.3%)     +136 B  (+0.5%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@holdercp
Copy link
Contributor Author

I welcome any pushback on the approach I've taken here. I think I've made the better tradeoff but I'd love to hear some more opinions.

@holdercp holdercp force-pushed the fix/recent-feed-pagination branch from 3f2a1a9 to 37a9663 Compare January 9, 2025 22:41
@holdercp holdercp requested a review from eoigal January 9, 2025 22:49
@matticbot
Copy link
Contributor

matticbot commented Jan 9, 2025

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • notifications
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug fix/recent-feed-pagination on your sandbox.

@holdercp holdercp force-pushed the fix/recent-feed-pagination branch from 37a9663 to 03303df Compare January 9, 2025 23:00
Copy link
Member

@allilevine allilevine left a comment

Choose a reason for hiding this comment

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

This is working for me. ✅ I did see the request hang when initially changing the number of items to display per page (from 10 to 100, in the gear icon) but I couldn't replicate it.

I wish we could fix this on the back-end, but it's great that this allows us to enable pagination again. 🙌

postId: string;
}

function isPaddingItem( item: ReaderPost | PaddingItem ): item is PaddingItem {
Copy link
Member

Choose a reason for hiding this comment

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

TIL about this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's really useful, especially when using Array.filter(). If you search around for "type guard using type predicate" you can learn more. Here's the section from the TS guide.


// This is a temporary fix to disable the pagination page selector because of this issue: Automattic/loop#247
// Once that issue is fixed, this code should be removed.
.dataviews-pagination__page-select {
Copy link
Member

Choose a reason for hiding this comment

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

🎉


switch ( action.type ) {
case READER_STREAMS_PAGE_RECEIVE:
gap = action.payload.gap;
streamItems = action.payload.streamItems;
perPage = action.payload.perPage;
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 optional chaining here like on action.payload?.streamKey? below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it would make a difference because perPage would be set to undefined either way.

I do notice now that I broke from this "destructuring" pattern when accessing action.payload.streamKey so I'll change that to make it consistent.

@holdercp holdercp merged commit 52aefdf into trunk Jan 10, 2025
12 checks passed
@holdercp holdercp deleted the fix/recent-feed-pagination branch January 10, 2025 16:00
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jan 10, 2025
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.

3 participants