Skip to content

Conversation

@dhasilva
Copy link
Contributor

@dhasilva dhasilva commented Nov 21, 2025

Follow-up to #45912

Proposed changes:

  • Fixes an issue where undoing an action reloaded the wrong page
  • Addresses code review comments
  • Adds a notice while updating the status, after optimistic update
  • Sets the page to loading state if all items from the page are optimistically moved

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

p1763124260359199/1763124228.578279-slack-C052XEUUBL4

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

Testing instructions:

  • Go to the seconds page of the inbox
  • Trash a response or mark it as spam
  • Check that a notice with a spinner icon is displayed until the action is finished on the server side
  • Click on Undo
  • Check that the second page items are kept (without the PR, the first page is loaded if spam/trash have only one page)
  • Now select all items from the page and trash/mark as spam
  • Check that the page displays the loading screen instead of the empty page

@github-actions
Copy link
Contributor

github-actions bot commented Nov 21, 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 update/forms-optimistic-load-screen branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/forms-optimistic-load-screen

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 21, 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!

@jp-launch-control
Copy link

jp-launch-control bot commented Nov 21, 2025

Code Coverage Summary

Coverage changed in 6 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/dashboard/inbox/stage/actions.tsx 0/363 (0.00%) 0.00% 111 💔
projects/packages/forms/src/dashboard/store/reducer.js 37/61 (60.66%) -1.61% 4 💔
projects/packages/forms/src/dashboard/store/actions.js 14/23 (60.87%) -5.80% 2 ❤️‍🩹
projects/packages/forms/src/dashboard/store/selectors.js 22/26 (84.62%) -6.29% 2 ❤️‍🩹
projects/packages/forms/src/dashboard/store/action-types.js 11/11 (100.00%) 0.00% 0 💚

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

@dhasilva dhasilva force-pushed the update/forms-optimistic-load-screen branch from 2a3daaf to a5dd0d3 Compare November 24, 2025 20:15
@dhasilva dhasilva added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. and removed [Status] In Progress labels Nov 24, 2025
@dhasilva dhasilva requested a review from a team November 24, 2025 21:47
@dhasilva dhasilva added I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. and removed I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. labels Nov 25, 2025
invalidateCacheAndNavigate( registry, getCurrentQuery(), queryParams, 'trash' );
}

requestAnimationFrame( () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think requestAnimationFrame doesn't guarantee cache invalidation is complete. It just schedules for the next paint. If cache invalidation takes longer, you might remove the pending action before data refetches, causing a brief flash of empty/old data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I had to use getEntityRecords to ensure the data is loaded before setting the pending action as resolved. Good catch. I was testing with the trash action, which reloaded faster.

@dhasilva dhasilva force-pushed the update/forms-optimistic-load-screen branch from 771e74f to 27825be Compare November 25, 2025 21:59
Copy link
Contributor

@vianasw vianasw left a comment

Choose a reason for hiding this comment

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

Cache invalidation is a really hard problem! I tested it again, and the flickering still persists when I undo an action (mark as spam, send to trash). Upon investigation, here is what I discovered:

  1. Mark spam: API call → response arrives → receiveEntityRecords(spam) auto-called by WordPress
  2. Undo clicked: optimistic update → editEntityRecord(publish)
  3. First API's receiveEntityRecords(spam) arrives → overwrites the undo's optimistic edit → flicker!
  4. Undo API completes → receiveEntityRecords(publish)

I think I have a fix that involves waiting for the original action to complete, but adds a slight delay. I'll follow up on Slack.

Fixes a race condition where clicking undo immediately after marking a
response as spam/trash would cause the UI to flicker. The item would
briefly disappear and reappear, and checkboxes would flash on all entries.

Root cause: When undo was clicked, the original action's API response
would arrive after the undo's optimistic update, overwriting it with
stale data. This created a sequence where the UI would update to the
wrong state (spam) before correcting itself (publish).

Solution: Make undo wait for the original action's refetch to complete
before starting. Implemented by:
- Tracking pending refetch promises in a Map by actionId
- Making undo onClick async and awaiting the original refetch
- Using undoTriggered flag to skip refetch if undo clicked quickly
- Removing original pending action state before starting undo

This ensures only one refetch result is applied, eliminating the flicker
while keeping undo responsive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Contact Form I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Package] Forms [Status] Needs Review This PR is ready for review. [Tests] Includes Tests [Type] Bug When a feature is broken and / or not performing as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants