Skip to content

Forms: fix phantom unread counter badge when no submissions are unread#47281

Open
kraftbj wants to merge 1 commit intotrunkfrom
forms-phantom-unread-badge
Open

Forms: fix phantom unread counter badge when no submissions are unread#47281
kraftbj wants to merge 1 commit intotrunkfrom
forms-phantom-unread-badge

Conversation

@kraftbj
Copy link
Contributor

@kraftbj kraftbj commented Feb 23, 2026

Fixes FORMS-592

Proposed changes:

The Jetpack admin sidebar shows a phantom red badge next to the Jetpack menu even when there are zero unread form submissions. The badge has class jp-feedback-unread-counter count-1 awaiting-mod—it looks like an unread Forms submission, but it isn't one.

The root cause is Forms' unread_count() method absorbing other badges from the Jetpack top-level menu and re-emitting them as Forms-styled badges. Here's the chain:

  1. My Jetpack's maybe_show_red_bubble() runs at admin_init:1001 and appends <span class="awaiting-mod">N</span> to the Jetpack menu for things like backup failures, missing connections, expiring plans, etc.
  2. Forms' unread_count() runs later at current_screen, finds the Jetpack menu item, and calls parse_menu_item() which extracts the awaiting-mod badge value.
  3. That extracted count gets added to $jetpack_badge_count (starting at the Forms unread count of 0), then Forms writes a new jp-feedback-unread-counter count-1 badge back to the menu—replacing My Jetpack's badge entirely.

I confirmed this on a live site: the REST endpoint my-jetpack/v1/red-bubble-notifications returned a backup_failure alert, the server-rendered HTML showed data-unread-diff='1' (meaning Forms unread = 0 but 1 "other" count was absorbed), and the Forms submenu correctly showed count-0. The top-level Jetpack badge was purely the absorbed My Jetpack alert, presented misleadingly as a Forms counter.

The intermittent nature reported in the ticket makes sense—the My Jetpack red bubble uses a transient cache. When the cache is empty, no server-side badge gets added (an async JS fetch runs instead), so the phantom badge disappears. On next page load, if the cache has been repopulated, it reappears.

The fix: skip writing the Forms badge when $unread is 0. My Jetpack's own badge stays untouched. When Forms does have unread items, behavior is unchanged—the combined badge with data-unread-diff still works.

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

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

No.

Testing instructions:

  1. Set up a site with Jetpack + Forms and 0 unread form submissions.
  2. Trigger at least 1 My Jetpack red bubble alert (e.g., disconnect backup, let a plan expire, or any condition that causes Red_Bubble_Notifications::get_red_bubble_alerts() to return a non-silent alert).
  3. Before the fix: The Jetpack top-level menu shows a count-1 badge with jp-feedback-unread-counter class. The Forms submenu shows count-0.
  4. After the fix: The Jetpack top-level menu shows My Jetpack's own awaiting-mod badge (not wrapped in jp-feedback-unread-counter), or no badge if there are no alerts. The Forms submenu shows no badge.
  5. Confirm that when there ARE unread Forms submissions, the combined badge still works correctly (Forms count + any existing Jetpack badge count).

Changelog

  • Generate changelog entries for this PR (using AI).

When Forms has 0 unread submissions, unread_count() was absorbing the
My Jetpack red bubble notification count and re-emitting it as a
Forms-styled badge (jp-feedback-unread-counter). This made it look like
there were unread form submissions when there were none.

Skip writing both the main menu and submenu badges when $unread is 0,
letting My Jetpack's own badge remain as-is.
Copilot AI review requested due to automatic review settings February 23, 2026 16:09
@kraftbj kraftbj added Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. labels Feb 23, 2026
@kraftbj kraftbj self-assigned this Feb 23, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2026

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 forms-phantom-unread-badge branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack forms-phantom-unread-badge

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

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 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 bug where the Jetpack admin sidebar displayed a phantom red "1" badge next to the Jetpack menu when there were zero unread form submissions but My Jetpack had alerts. The root cause was that Forms' badge rendering logic would absorb and re-emit My Jetpack's notification count using Forms' CSS class, making it appear as if there was an unread form submission.

Changes:

  • Added conditional checks to skip badge rendering when Forms has zero unread submissions
  • Preserved existing combined badge behavior when Forms does have unread items

Reviewed changes

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

File Description
projects/packages/forms/src/contact-form/class-contact-form-plugin.php Added if ( $unread > 0 ) guards around main menu and submenu badge rendering logic to prevent phantom badges
projects/packages/forms/changelog/forms-phantom-unread-badge Added changelog entry documenting the patch-level bug fix

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

@jp-launch-control
Copy link

jp-launch-control bot commented Feb 23, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-contact-form-plugin.php 568/1484 (38.27%) -0.05% 2 ❤️‍🩹

Full summary · PHP report · JS report

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants