[Components - ToggleGroupControl]: Fix extra update on incoming change#37224
Conversation
mcsf
left a comment
There was a problem hiding this comment.
Looks good, although the manual two-way binding with the twin useUpdateEffect hooks is something I found surprising.
packages/components/src/toggle-group-control/toggle-group-control/component.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
The changes test well as per instructions, and do fix the issue reported in #37172
I just wonder if this change in behavior could be unexpected for a consumer of this component, in case they expected the onChange callback to fire every time there's a change in value, regardless of whether the change is "external" or "internal"
In any case, could we also add a couple of doc changes:
I think we should base the behavior of all the components on the behavior of the regular elements (input...) and onChange is not called there if it's an external change. |
ciampo
left a comment
There was a problem hiding this comment.
I think we should base the behavior of all the components on the behavior of the regular elements (input...) and onChange is not called there if it's an external change.
That sounds reasonable, let's go ahead and merge these changes once the CHANGELOG is updated
Fixes: #37172
There was a bug in
ToggleGroupControlcomponent where it would call the passedonChangefunction during rendering an extra time where the value was the result of an incoming change (redo/undo). That would cause an extra level in history which was the same with the previous one, due to internal logic of handling history steps.Testing instructions (from the issue 😄 )
** noting that to reproduce the bug we have to also have at least one more typography setting which is handled by
styleobject property. This is needed because it has to do with internals detection ofmarkinghistory steps.Before
Screen.Recording.2021-12-08.at.4.27.48.PM.mov
After
after.mov