Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioGroup: Log deprecation warning #68067

Merged
merged 4 commits into from
Dec 18, 2024
Merged

RadioGroup: Log deprecation warning #68067

merged 4 commits into from
Dec 18, 2024

Conversation

mirka
Copy link
Member

@mirka mirka commented Dec 17, 2024

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
Copy link

github-actions bot commented Dec 17, 2024

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 <[email protected]>
Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: tyxla <[email protected]>

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

Copy link

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
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
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
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
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
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
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
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.

Copy link
Member

@tyxla tyxla left a comment

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
68 checks passed
@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
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