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

Toggling any module ON on Jetpack settings results in React warning #40086

Open
manzoorwanijk opened this issue Nov 7, 2024 · 2 comments
Open
Assignees
Labels
Admin Page React-powered dashboard under the Jetpack menu [Platform] Atomic [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack Triaged [Type] Bug When a feature is broken and / or not performing as intended

Comments

@manzoorwanijk
Copy link
Member

manzoorwanijk commented Nov 7, 2024

Impacted plugin

Jetpack

Quick summary

When a Jetpack module is OFF and you try to turn it ON on Jetpack settings page, it results in the warning:

A component is changing an uncontrolled input to be controlled.

Image

Steps to reproduce

  • Goto Jetpack settings, e.g. /wp-admin/admin.php?page=jetpack#/discussion
  • Enable a module, e.g. Comments
  • Notice the warning in the browser console.

A clear and concise description of what you expected to happen.

There should be no warning.

What actually happened

A warning is shown in browser console

Impact

All

Available workarounds?

No and the platform is unusable

If the above answer is "Yes...", outline the workaround.

No response

Platform (Simple and/or Atomic)

Self-hosted, Atomic

Logs or notes

The bug seems to have been there for six years and the source of that bug is the OR (||) operator here. It should instead be a null coalescing operator.

checked={ this.props.activated || this.props.isModuleActivated }

- checked={ this.props.activated || this.props.isModuleActivated }
+ checked={ this.props.activated ?? this.props.isModuleActivated }
@manzoorwanijk manzoorwanijk added [Type] Bug When a feature is broken and / or not performing as intended Needs triage Ticket needs to be triaged labels Nov 7, 2024
@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack [Platform] Atomic [Pri] BLOCKER labels Nov 7, 2024
@jeherve jeherve added Admin Page React-powered dashboard under the Jetpack menu [Pri] Normal Triaged and removed [Pri] BLOCKER Needs triage Ticket needs to be triaged labels Nov 7, 2024
@anomiex
Copy link
Contributor

anomiex commented Nov 7, 2024

I note that ?? will give different results for two cases. One is what you intend, but the other probably isn't. And one that probably should be changed isn't being changed either, although due to

that case may not be able to happen.

this.props.activated this.props.isModuleActivated || ??
undefined undefined undefined undefined
undefined true true true
undefined false false false
true undefined true true
true true true true
true false true true
false undefined undefined false
false true true false
false false false false

In other words, if this.props.activated is false while this.props.isModuleActivated is true, changing to ?? will change it from checked to unchecked.

If we don't want that change, using this.props.activated || this.props.isModuleActivated || false, or ensuring that isModuleActivated is not undefined, or if activated already can't be undefined swapping it to this.props.isModuleActivated || this.props.activated would work better.

Or another possibility is that isModuleActivated never seems to be used in the first place, and I wonder if #8934 had intended for it to be used as something like this.props.isModuleActivated( this.props.slug ). We could just drop it entirely.

@manzoorwanijk
Copy link
Member Author

Yeah, I'm not sure about the logic here. ?? was just a thought.
Yeah, it will be good to get rid of that second condition.

@coder-karen coder-karen self-assigned this Nov 12, 2024
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 [Platform] Atomic [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack Triaged [Type] Bug When a feature is broken and / or not performing as intended
Projects
Development

No branches or pull requests

4 participants