appsmith icon indicating copy to clipboard operation
appsmith copied to clipboard

[Bug]: .isSwitched of a Switch-widget doesn't get the correct (updates) value

Open EsjeeDB opened this issue 9 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Description

Image Image

Image

Image

Steps To Reproduce

  1. Click 2 (or more) times on ToggleButton (note: one click seems mostly to work fine)
  2. The Switch-widget is updates correctly and also the (depending) MyButton is updated correctly (with disabled true or false)
  3. Click once on Switch-widget
  4. The switch-widget changes of course correct, BUT the (depending) MyButton is NOT updated correctly (with disabled true or false)
  5. I checked: the reason is on line 8: Switch.isSwitched doesn't have the correct value

Public Sample App

No response

Environment

Production

Severity

Medium (Frustrating UX)

Issue video log

No response

Version

Docker self-hosted, Appsmith v1.95 2 jan 2026

EsjeeDB avatar Feb 18 '26 19:02 EsjeeDB

APP-14903

linear[bot] avatar Feb 18 '26 19:02 linear[bot]

Proposed fix

Root cause: SwitchWidget stores isSwitchedOn as a meta property that defaults to defaultSwitchState. Once the user interacts with the Switch, the meta value takes precedence. Subsequent external changes to defaultSwitchState (e.g. via Switch1.setValue(...) driven by a ToggleButton) update defaultSwitchState but leave the stale meta isSwitchedOn in place, so widgets bound to Switch1.isSwitchedOn keep reading the old value.

The sibling CheckboxWidget already handles this in componentDidUpdate by syncing the meta when the derived value changes (app/client/src/widgets/CheckboxWidget/widget/index.tsx). SwitchWidget is missing the equivalent block.

Planned PR

  • Add a programmatic-change sync in SwitchWidget.componentDidUpdate so isSwitchedOn meta stays consistent when defaultSwitchState changes externally.
  • Add/extend tests covering the ToggleButton → Switch → dependent-widget chain.

File touched

  • app/client/src/widgets/SwitchWidget/widget/index.tsx

Happy to take this on will open a PR.

itsmejay80 avatar Apr 18 '26 22:04 itsmejay80