-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(Switch widget): sync isSwitchedOn meta on programmatic changes #41749
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
base: release
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -432,6 +432,14 @@ class SwitchWidget extends BaseWidget<SwitchWidgetProps, WidgetState> { | |
| ) { | ||
| this.props.updateWidgetMetaProperty("isDirty", false); | ||
| } | ||
|
|
||
| // Sync meta when isSwitchedOn changes programmatically so dependents don't see a stale value. | ||
| if (this.props.isSwitchedOn !== prevProps.isSwitchedOn) { | ||
| this.props.updateWidgetMetaProperty( | ||
| "isSwitchedOn", | ||
| this.props.isSwitchedOn, | ||
| ); | ||
|
Comment on lines
+436
to
+441
|
||
| } | ||
| } | ||
|
|
||
| onChange = (isSwitchedOn: boolean) => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sync block is gated by
this.props.onChange, butonChangeis optional and often unset in the repro (programmaticsetValue/bindings can updatedefaultSwitchStatewithout configuring the Switch’s own onChange). In that case this code never runs andisSwitchedOnmeta can still go stale. Remove the&& this.props.onChangeguard (and, if you want to avoid extra dispatches, consider keying the sync specifically offdefaultSwitchStatechanges instead ofisSwitchedOnchanges).