-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Components - ToggleGroupControl]: Fix extra update on incoming change #37224
[Components - ToggleGroupControl]: Fix extra update on incoming change #37224
Conversation
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.
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
ToggleGroupControl
component where it would call the passedonChange
function 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
style
object property. This is needed because it has to do with internals detection ofmarking
history steps.Before
Screen.Recording.2021-12-08.at.4.27.48.PM.mov
After
after.mov