Components: refactor ColorPicker to pass exhaustive-deps#41294
Components: refactor ColorPicker to pass exhaustive-deps#41294
ColorPicker to pass exhaustive-deps#41294Conversation
|
Size Change: -49 B (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
|
I'd been working on some other |
|
Awesome, thanks for jumping in @stokesman! I hadn't started in on |
| } | ||
| }, [] ); | ||
| } ); | ||
| useEffect( bottomSheetInitializer, [ bottomSheetInitializer ] ); |
There was a problem hiding this comment.
Hmm... I kind of prefer adding an eslint-disable with a TODO comment here instead of legitimizing the lifecycle-reliant approach of the code. I'm not sure how this component is consumed (or if it has third-party consumers), but it seems to be setting some potential bugs in stone. With an eslint-disable and TODO, we can at least flag that it's problematic. What do you think? (cc @geriux)
There was a problem hiding this comment.
I've gone ahead and changed to the eslint-disable + TODO comment in aa7a41b.
BTW, when I first worked on this I did (for my first time ever) run the iOS emulator to test and maybe see if I could better understand what this effect was for but I couldn't even find a ColorPicker to manipulate 🤷♂️.
|
I believe the ESLint config has recently been changed around some formatting options, let's rebase this PR to make sure that there are no conflicts or unexpected merge artifacts. |
602e251 to
f4aa7c4
Compare
|
Having another look at this I'm tempted to do a bit more refactoring for style. Particularly, in Diff to monopolize conditional for legacy handlingdiff --git a/packages/components/src/color-picker/use-deprecated-props.ts b/packages/components/src/color-picker/use-deprecated-props.ts
index cbe57a4e0e..a2cae51d20 100644
--- a/packages/components/src/color-picker/use-deprecated-props.ts
+++ b/packages/components/src/color-picker/use-deprecated-props.ts
@@ -107,30 +107,24 @@ const transformColorStringToLegacyColor = memoize(
export function useDeprecatedProps(
props: LegacyProps | ColorPickerProps
): ColorPickerProps {
- const isUsingLegacy = isLegacyProps( props );
const { onChangeComplete } = props as LegacyProps;
- const { onChange: onChangeProp } = props as ColorPickerProps;
const legacyChangeHandler = useCallback(
( color: string ) => {
onChangeComplete( transformColorStringToLegacyColor( color ) );
},
[ onChangeComplete ]
);
- const onChange = isUsingLegacy ? legacyChangeHandler : onChangeProp;
-
- const { color: colorProp } = props;
- const color = isUsingLegacy
- ? getColorFromLegacyProps( colorProp )
- : ( colorProp as ColorPickerProps[ 'color' ] );
-
- const { disableAlpha } = props as LegacyProps;
- const { enableAlpha: enableAlphaProp } = props as ColorPickerProps;
- const enableAlpha = isUsingLegacy ? ! disableAlpha : enableAlphaProp;
-
+ if ( isLegacyProps( props ) ) {
+ return {
+ color: getColorFromLegacyProps( props.color ),
+ enableAlpha: ! props.disableAlpha,
+ onChange: legacyChangeHandler,
+ };
+ }
return {
- ...( isUsingLegacy ? {} : props ),
- onChange,
- color,
- enableAlpha,
+ ...props,
+ color: props.color as ColorPickerProps[ 'color' ],
+ enableAlpha: ( props as ColorPickerProps ).enableAlpha,
+ onChange: ( props as ColorPickerProps ).onChange,
};
}
|
mirka
left a comment
There was a problem hiding this comment.
Having another look at this I'm tempted to do a bit more refactoring for style
Ah the dopamine hit I got from this refactor. Yes please.
|
👋 I see there's still a pending review item but wanted to chime in to say that I'm available to review/test this PR from the native-side when needed. |
ciampo
left a comment
There was a problem hiding this comment.
Hey @stokesman , thank you for working on this!
- ✅ Lena's feedback has been addressed
- ✅ Overall code changes LGTM
- ✅ Tested web version of the legacy
ColorPickerin Storybook, works fine - ❓ Native version of the component needs testing
@SiobhyB would you mind taking a look at the native component and potentially give a final approval to this PR? Thank you! 🙏
There was a problem hiding this comment.
I tested this on the native side and couldn't spot any regressions in the colour picker. I tested a number of different changes to the background and foreground colour of both a paragraph and a button block. Along the way, I went through the color settings test cases and made sure to experiment with the different options e.g. solid, theme defaults, custom, gradients, etc. All looks good to me! Thanks for including us in this, all :)
|
Thank you @SiobhyB for your review, and thank you @stokesman as always for your contributions, always very appreciated! Could you just add a CHANGELOG entry before merging? |
a2b1a2b to
1e6a2aa
Compare
|
Thank you Marco and Siobahn for the reviews and testing. Special thanks to Lena for the thorough advice! |
What?
Updates the
ColorPickercomponent to satisfy theexhaustive-depseslint ruleWhy?
Part of the effort in #41166 to apply
exhuastive-depsto the Components packageHow?
in
useDeprecatedPropspropsfrom within a callback hookin native component
setColorpassed by props in favor of calling from event handlers.react-hooks/exhaustive-depsrule for an effect hook and left a TODO comment about revisiting it.Testing Instructions
npx eslint --rule 'react-hooks/exhaustive-deps: warn' packages/components/src/color-pickerWhat's missing?
A changelog entry but I've left that out for now in case this requires some more time.