Skip to content

RadioGroup: Log deprecation warning - #68067

Merged
mirka merged 4 commits into
trunkfrom
deprecate-radiogroup
Dec 18, 2024
Merged

mirka merged 4 commits into
trunkfrom
deprecate-radiogroup

Conversation

@mirka

@mirka mirka commented Dec 17, 2024 •

Copy link
Copy Markdown
Member

What?

Soft deprecates (#61099) the RadioGroup component.

Why?

All remaining instances of RadioGroup in the app have been removed as of #67702.

How?

This was already passive deprecated, so just escalating the deprecation so it notifies consumers through a console warning and Dev Note.

Testing Instructions

Go to the Storybook for RadioGroup and check that the deprecation warning is being logged in dev tools.

✍️ Dev Note

The RadioGroup component has been deprecated. To be consistent with the current WordPress design system, use RadioControl or ToggleGroupControl instead.

@mirka mirka added [Type] Code Quality Issues or PRs that relate to code quality [Package] Components /packages/components Needs Dev Note Requires a developer note for a major WordPress release cycle labels Dec 17, 2024
@mirka
mirka requested a review from a team December 17, 2024 19:31
@mirka mirka self-assigned this Dec 17, 2024
@mirka
mirka requested a review from ajitbohra as a code owner December 17, 2024 19:31
@github-actions

github-actions Bot commented Dec 17, 2024 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

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

@github-actions

Copy link
Copy Markdown

Flaky tests detected in a78d424.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12380096509
📝 Reported issues:

@mirka mirka added has dev note when dev note is done (for upcoming WordPress release) and removed Needs Dev Note Requires a developer note for a major WordPress release cycle labels Dec 17, 2024
since: '6.8',
alternative: 'wp.components.ToggleGroupControl',
} );
if ( ! __shouldNotWarnDeprecated ) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Adds a mechanism to suppress a confusing "double warning" coming from the ButtonGroup used internally in RadioGroup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

React uses global variables for this purpose:

let didWarnAboutSomething = false;
function something() {
  if ( ! didWarnAboutSomething ) {
    didWarnAboutSomething = true;
    console.error( /* ... */ );
  }
}

They also use Sets as didWarn* values, when they want to track a warning for each component name or something else separately.

We could use this, too, instead of the semi-official prop.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we decide to go the didWarn way, I think it makes sense to implement it directly in the deprecated() helper function.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was thinking about smarter ways to implement this mechanism when I started logging the size deprecation warnings, but came to the conclusion that an explicit prop was the only way. I am imagining consumer code like this, where the ButtonGroup warning inside the RadioGroup should be suppressed, but the standalone ButtonGroup instance should still warn:

const MyUI = () => (
  <RadioGroup />
  <ButtonGroup />
);

I'm all ears if you have any clever ideas!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could component's internal context system help?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not in a way that's "more automatic" than the current manual prop-based system, I don't think. Also context could be problematic when render props or slots are involved (e.g. we don't want to suppress warnings on a component that the consumer passed in through a prefix prop).

if ( ! __shouldNotWarnDeprecated ) {
deprecated( 'wp.components.ButtonGroup', {
since: '6.8',
alternative: 'wp.components.__experimentalToggleGroupControl',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added the __experimental prefix for consistency.

@tyxla tyxla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tests well and code LGTM 👍

@mirka
mirka merged commit 6154c34 into trunk Dec 18, 2024
@mirka
mirka deleted the deprecate-radiogroup branch December 18, 2024 18:24
@github-actions github-actions Bot added this to the Gutenberg 20.0 milestone Dec 18, 2024
@Mamaduka Mamaduka mentioned this pull request Mar 12, 2025
45 of 49 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has dev note when dev note is done (for upcoming WordPress release) [Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants