Skip to content

RFC: Self-managing NewBadge / BetaBadge backed by an auto-expiring registry#48180

Draft
nerrad wants to merge 1 commit intotrunkfrom
try/new-feature-badge-registry
Draft

RFC: Self-managing NewBadge / BetaBadge backed by an auto-expiring registry#48180
nerrad wants to merge 1 commit intotrunkfrom
try/new-feature-badge-registry

Conversation

@nerrad
Copy link
Copy Markdown
Contributor

@nerrad nerrad commented Apr 19, 2026

Proof-of-concept / RFC. Not for merge as-is. See #48162 for the actual Chip migration.

Problem

<Badge>New</Badge> plus a // TODO: remove once not "new" comment is the standard pattern. Those TODOs rot — the one this PR replaces in composing.jsx was added in #38414 in July 2024 (21 months ago).

Proposal

Drive "New"/"Beta" badges from a tiny per-plugin registry that auto-expires entries:

// _inc/client/lib/new-features/index.ts
export const NEW_FEATURES = [
    { slug: 'jetpack-ai', addedAt: '2024-07-22', durationDays: 365 },
];
// any consumer
<NewBadge feature="jetpack-ai" />

<NewBadge> and <BetaBadge> consume useNewFeature(slug) which checks the registry + the date window and returns null when the feature isn't flagged or the window has elapsed. No consumer change needed when a feature ages out — registry edits drive the lifecycle.

What's in this PR

  • _inc/client/lib/new-features/index.ts — registry, types, useNewFeature hook
  • _inc/client/components/new-badge/index.tsx<NewBadge> and <BetaBadge>
  • composing.jsx migrated from <Chip type="new" text={...} /> + the 21-month TODO → <NewBadge feature="jetpack-ai" />

Out of scope

  • Migrating other "new"-pill consumers (Recommendations, My Jetpack AI interstitial, Boost <Pill>, Protect badges) — would follow if the pattern is approved.
  • ESLint rule that warns on expired entries — mentioned in the design discussion, not built here.
  • Promoting <NewBadge> / <BetaBadge> to js-packages/components — defer until the pattern proves itself in one plugin.
  • Tests — the hook is trivially testable; tests would land before merge if the pattern is approved.

Looking for

Yes/no on the pattern. Bikeshed on the registry shape (date-based vs. version-based expiry, where it lives, whether to also gate via PHP).

Related

…g registry

Adds `lib/new-features` (registry + `useNewFeature` hook) and
`components/new-badge` (`<NewBadge>` / `<BetaBadge>`) to plugins/jetpack
as a proof-of-concept for an alternative pattern: instead of inline
`<Badge>New</Badge>` plus a TODO that rots, consumers write
`<NewBadge feature="jetpack-ai" />` and the badge silently disappears
once its registered window expires. Registry edits, not code edits, drive
the lifecycle.

Migrates the writing/composing.jsx AI Assistant badge as the demo
consumer — replacing the Chip + 21-month-old TODO comment from #38414
with a single self-managing component.

Scoped to plugins/jetpack to keep the proposal small and reviewable.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 19, 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 try/new-feature-badge-registry branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack try/new-feature-badge-registry

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 github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Admin Page React-powered dashboard under the Jetpack menu labels Apr 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 19, 2026

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 🤖


🔴 Action required: Please include detailed testing steps, explaining how to test your change, like so:

## Testing instructions:

* Go to '..'
*

🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:

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

My PR adds *x* and *y*.

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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: May 5, 2026
    • Code freeze: May 4, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

}
return (
<Badge intent="stable">
{ _x( 'New', 'Indicates a recently-launched feature.', 'jetpack' ) }
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.

Does, text need to be customizable?

* @return The Badge, or null when the feature isn't flagged or has expired.
*/
export function BetaBadge( { feature }: Props ) {
if ( ! useNewFeature( feature, 'beta' ) ) {
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.

Beta might need to be something that is not expirable and automatically hidden, since usually that is usually manually decided. Still with the registry, we could at least automate some sort of check for pinging folks if a beta thing sits at beta for "x" time period after the set "expiry"

* @param props.feature - Slug registered in `lib/new-features`.
* @return The Badge, or null when the feature isn't flagged or has expired.
*/
export function NewBadge( { feature }: Props ) {
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.

I wonder if expiry should just be a prop. Then we could likely more easily automate some sort of code cleanup action on every Jetpack release to get rid of expired badges direclty in the code.

Comment on lines +37 to +44
export const NEW_FEATURES: readonly NewFeatureEntry[] = [
{
slug: 'jetpack-ai',
addedAt: '2024-07-22',
durationDays: 365,
note: 'AI Assistant entry link added in #38414. Flagged retroactively to demo the registry pattern.',
},
];
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.

As noted in a separate comment, I'm not sure about the registry pattern (and instead maybe include that via props on the actual badge wrapper component).

@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

2 files are newly checked for coverage.

File Coverage
projects/plugins/jetpack/_inc/client/components/new-badge/index.tsx 0/6 (0.00%) 💔
projects/plugins/jetpack/_inc/client/lib/new-features/index.ts 0/8 (0.00%) 💔

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

Admin Page React-powered dashboard under the Jetpack menu [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant