Skip to content

Conversation

@enejb
Copy link
Member

@enejb enejb commented Nov 1, 2025

Currently when you remove items from the last page, the request for content on the page returns a 400 error which results the state of the page freezing.

This is fixed by making sure that we invalidate and navigate away from the last page if we notice that there is nothing on the last page.

Before:

Screen.Recording.2025-11-01.at.12.57.04.PM.mov

After:

Screen.Recording.2025-11-01.at.12.58.43.PM.mov

Fixes FORMS-361

Proposed changes:

  • Implement a invalidateCacheAndNavigate function that we can call on all the bulk actions that.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

See FORMS-361

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • On trunk (to replicate the bug)
  • Create multiple pages of trashed items.
  • On the last page mark all the items as spam.
  • Notice that you end up on the last page with everything freeszing.

Now switch to this branch and follow the same steps as above.
Notice that you end up on the correct page as expected.

enejb added 2 commits November 1, 2025 12:01
Introduces a helper function, invalidateCacheAndNavigate, to centralize cache invalidation and page navigation logic after bulk actions (spam, not spam, restore, trash, delete) in the inbox dataviews. This ensures accurate counts and correct pagination after items are removed from inbox, spam, or trash, improving consistency and maintainability.
@enejb enejb requested review from a team and Copilot November 1, 2025 20:00
@enejb enejb added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. [Package] Forms labels Nov 1, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/forms-second-page branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/forms-second-page

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2
@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a pagination error that occurs when removing items from the forms inbox, spam, or trash views. When the last items on a page are removed, the user should be navigated to the last valid page rather than remaining on a now-empty invalid page.

Key Changes

  • Added invalidateCacheAndNavigate helper function to handle cache invalidation and page navigation after item removal
  • Integrated the helper into markAsSpamAction, markAsNotSpamAction, restoreAction, moveToTrashAction, and deleteAction
  • The helper calculates the new total pages based on remaining item counts and navigates to the last valid page if needed

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
projects/packages/forms/src/dashboard/inbox/dataviews/actions.js Added invalidateCacheAndNavigate helper function and integrated it into all item removal actions to prevent invalid page states
projects/packages/forms/changelog/fix-forms-second-page Added changelog entry documenting the pagination fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +71
statusBeingRemovedFrom
) => {
// Invalidate entity records cache for current view
registry
.dispatch( coreStore )
.invalidateResolution( 'getEntityRecords', [ 'postType', 'feedback', currentQuery ] );

// Invalidate counts to ensure accurate totals
registry.dispatch( dashboardStore ).invalidateCounts();

// Navigate to correct page if current page will be invalid
const { getTrashCount, getSpamCount, getInboxCount } = registry.select( dashboardStore );
const { setCurrentQuery } = registry.dispatch( dashboardStore );

// Get the appropriate count based on which status we're removing from
const countGetters = {
trash: getTrashCount,
spam: getSpamCount,
inbox: getInboxCount,
};
const remainingCount = countGetters[ statusBeingRemovedFrom ]( queryParams );

Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

The count selectors are called immediately after invalidating counts, which returns the stale optimistic counts from the state cache rather than the actual remaining count after item removal. This causes incorrect pagination calculations. The optimistic count updates happen before items are removed, so the counts used here don't reflect the actual post-removal state. Consider calculating the remaining count by subtracting the number of successfully removed items from the current count, or calling the selectors before invalidation to use the optimistic values intentionally.

Suggested change
statusBeingRemovedFrom
) => {
// Invalidate entity records cache for current view
registry
.dispatch( coreStore )
.invalidateResolution( 'getEntityRecords', [ 'postType', 'feedback', currentQuery ] );
// Invalidate counts to ensure accurate totals
registry.dispatch( dashboardStore ).invalidateCounts();
// Navigate to correct page if current page will be invalid
const { getTrashCount, getSpamCount, getInboxCount } = registry.select( dashboardStore );
const { setCurrentQuery } = registry.dispatch( dashboardStore );
// Get the appropriate count based on which status we're removing from
const countGetters = {
trash: getTrashCount,
spam: getSpamCount,
inbox: getInboxCount,
};
const remainingCount = countGetters[ statusBeingRemovedFrom ]( queryParams );
statusBeingRemovedFrom,
numRemoved
) => {
// Get the appropriate count based on which status we're removing from, before invalidation
const { getTrashCount, getSpamCount, getInboxCount } = registry.select( dashboardStore );
const { setCurrentQuery } = registry.dispatch( dashboardStore );
const countGetters = {
trash: getTrashCount,
spam: getSpamCount,
inbox: getInboxCount,
};
const currentCount = countGetters[ statusBeingRemovedFrom ]( queryParams );
const remainingCount = Math.max(0, currentCount - numRemoved);
// Invalidate entity records cache for current view
registry
.dispatch( coreStore )
.invalidateResolution( 'getEntityRecords', [ 'postType', 'feedback', currentQuery ] );
// Invalidate counts to ensure accurate totals
registry.dispatch( dashboardStore ).invalidateCounts();
Copilot uses AI. Check for mistakes.

// If there is at least one successful update, invalidate the cache and navigate if needed
if ( itemsUpdated.length ) {
invalidateCacheAndNavigate( registry, getCurrentQuery(), queryParams, 'inbox' );
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

The statusBeingRemovedFrom parameter is hardcoded to 'inbox', but moveToTrashAction can be triggered from items with any status (see isEligible: item => item.status !== 'trash' at line 358). Items could be in 'spam' or 'publish' status. This should use the actual status of the items being moved, not a hardcoded value, otherwise pagination calculations will use the wrong count.

Suggested change
invalidateCacheAndNavigate( registry, getCurrentQuery(), queryParams, 'inbox' );
// Use the actual status of the items being moved, not a hardcoded value
invalidateCacheAndNavigate( registry, getCurrentQuery(), queryParams, items[0]?.status );
Copilot uses AI. Check for mistakes.
@enejb enejb force-pushed the fix/forms-second-page branch from adfc176 to 1272c21 Compare November 1, 2025 20:03
@jp-launch-control
Copy link

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/dashboard/inbox/dataviews/actions.js 0/233 (0.00%) 0.00% 23 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Contact Form [Package] Forms [Status] Needs Review This PR is ready for review. [Type] Bug When a feature is broken and / or not performing as intended

2 participants