Skip to content

fix(rsvp): ignore an older guest count save - #2650

Open
faisalahammad wants to merge 4 commits into
GatherPress:developfrom
faisalahammad:fix/2641-ignore-older-guest-count-save
Open

faisalahammad wants to merge 4 commits into
GatherPress:developfrom
faisalahammad:fix/2641-ignore-older-guest-count-save

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2641

Proposed changes:

  • Guest count saves in the RSVP block now send a save_page ID (made once per page load) and a save_order number that goes up with each change.
  • POST gatherpress/v1/rsvp checks the order stored on the RSVP comment (gatherpress_rsvp_save_order meta). If the same page already saved a same or higher order, the request skips the save and returns the stored RSVP. Otherwise it stores the new order and saves as before.
  • The meta keeps the order per page, for the last five pages, so a save from another tab or device is never blocked.
  • Requests without these fields (anonymous toggle, status changes, other callers) work as before.

Before, a save sent on page leave (with keepalive) could reach the server after an older save that was still on its way. The older guest count then won.

One known limit: two requests from the same page that run in PHP at the exact same moment can still race. The window is milliseconds, and closing it would need a lock around the check and the save.

Other information:

  • Have you written new tests for your changes, if applicable?

AI assistance

  • An AI tool wrote a significant part of this change.

Testing instructions:

Setup: create a future event with Maximum Number of Guests set to 5 or more. Log in, open the event on the front end, and RSVP as Attending. Open dev tools, Network tab, filtered on rsvp.

Test 1: normal save

  1. Change the guest count to 3 and wait about a second.
  2. One rsvp request is sent with guests: 3, save_page and save_order.
  3. Reload. The count shows 3.

Test 2: older save arriving last is ignored

  1. Set network throttling to Slow 3G.
  2. Change the count to 2 and wait for its request to start.
  3. While it is pending, change the count to 4 and leave the page at once.
  4. Turn throttling off and open the event again.
  5. The count shows 4, not 2.

Test 3: other tabs are not blocked

  1. Open the event in two tabs.
  2. Change the count to 4 in tab A, then to 1 in tab B.
  3. Reload. The count shows 1.

Test 4: other actions unchanged

  1. Toggle anonymous, switch to Not Attending, then back to Attending.
  2. Each change saves as before, without save_page or save_order.

Credit (for release notes)

My WordPress.org username: faisal03

Changelog entry

The entry is committed in .github/changelog/2641-guest-count-save-order.

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Keep the newest guest count when an older save reaches the server after it, such as when the page is left during a save.

- Send a page ID and a save order with each guest count save.
- Skip a save in the RSVP endpoint when a same or newer order from the same page is already stored, and return the stored RSVP.
- Keep the order of the last five pages in comment meta, so tabs do not block each other.
- Add PHP and JS tests and a changelog entry.

Why: a save sent on page leave can reach the server after an older save that is still on its way, and the older count then wins.

Fixes GatherPress#2641
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props faisalahammad, mauteri.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Test Coverage Report

✅ All coverage checks passed!

✅ PHP Coverage
=== PR Coverage Check ===

Configuration loaded:
  Minimum coverage: 100%
  Exclude patterns: 47 patterns
  Low coverage exceptions: 0 files

Checking coverage for files changed from origin/develop...

Found 2 changed PHP file(s):
  - includes/core/classes/event/class-rest-api.php
  - test/unit/php/includes/tests/core/classes/event/class-test-rest-api.php

Files requiring coverage check: 1
  - includes/core/classes/event/class-rest-api.php

✅ Loaded coverage.xml
✅ Loaded coverage-multisite.xml

✅ includes/core/classes/event/class-rest-api.php - 100% coverage (482/482 lines)

=== Summary ===
✅ Passed: 1 file(s)
⏭️  Excluded: 1 file(s)
❌ Failed: 0 file(s)

✅ All changed files meet the minimum coverage requirement of 100%
✅ JavaScript Coverage
=== PR JavaScript Coverage Check ===

Configuration loaded:
  Minimum coverage: 100%
  Exclude patterns: 47 patterns

Checking coverage for JavaScript files changed from origin/develop...

Found 2 changed JavaScript file(s):
  - src/blocks/rsvp/view.js
  - src/helpers/interactivity.js

✅ All changed JavaScript files are excluded from coverage checks.
Changed files match exclusion patterns from sonar-project.properties

This comment is automatically updated on each push.

- Rename find_newer_save() to save_in_order(), which now does the save too.
- Drop the ternary from update_rsvp() and the unused State import.

Why: the ternary pushed the NPath complexity of update_rsvp() over the PHP Mess Detector limit.
@mauteri mauteri added this to the 0.38.0 milestone Nov 16, 2026
@mauteri
mauteri requested review from mattcowan and mauteri November 16, 2026 14:36

@mattcowan mattcowan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix works as described. One inline comment, the server takes whatever the browser sends for the two new fields. A bad value causes a PHP warning or puts a very long string into the database. Declaring the fields lets WordPress refuse bad values before the code runs.

- Declare save_page (string, max 64) and save_order (integer, min 1)
  in the rsvp route args so WordPress refuses bad values with a 400.
- Add a dispatch test for refused and accepted values.

Addresses PR feedback.

Refs GatherPress#2650

@faisalahammad faisalahammad left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mattcowan thanks for the review. I added the route args you asked for in 4d96326, with a test that sends requests through the route. I also merged the latest develop. Can you take another look when you have time?

@github-actions

Copy link
Copy Markdown
Contributor

Preview changes with Playground

Customize PR Playground

To customize the Playground preview for this specific PR, create a file at:

.github/playground/PR-2650-blueprint-override.json

The override is merged into the generated blueprint and can be used to:

  • Enable Playground features
  • Install additional plugins
  • Change site options
  • Run steps before or after the GatherPress' default steps

Example:

{
	"$schema": "https://gatherpress.org/playground-preview/pr-override-schema.json",
	"landingPage": "/wp-admin/edit.php?post_type=gatherpress_venue",
	"siteOptions": {
		"show_on_front": "page"
	},
	"features": {
		"networking": true
	},
	"prependSteps": [
		{
			"step": "installPlugin",
			"pluginData": {
				"resource": "wordpress.org/plugins",
				"slug": "simple-location"
			},
			"options": {
				"activate": true
			}
		}
	],
	"appendSteps": [
		{
			"step": "runPHP",
			"code": ""
		}
	]
}

Go to Playground PR preview customization for more details.

You can preview the recent changes for PR#2650 with the following PHP versions:

PHP Version 8.4

PHP Version 8.2

PHP Version 8.1

Download .zip with build changes

Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions.

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.

Ignore an older guest count save that reaches the server after a newer one

3 participants