Skip to content
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

fix(resize-handle): make ref callback stable #214

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Aug 14, 2024

See comments on code.

@@ -48,7 +48,7 @@ export type UseResizeHandleParams = {
* A function that will be called to get the value that will be set as the aria-valuetext attribute on the resize handle.
* Use this for localization.
*/
getA11ValueText?: (value: number) => string;
getA11ValueText?: (value: number) => string | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually allows undefined, the default impl also returns undefined.

Comment on lines +84 to +88
const handleChange: UseResizeHandleParams['onChange'] = useEventCallback(
(value) => {
onChange?.(value);
}
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use useEventCallback() callback there, otherwise we make memoization an implicit contract

@@ -68,8 +72,7 @@ export const useResizeHandle = (params: UseResizeHandleParams) => {
onChange,
onDragStart,
onDragEnd,
getA11ValueText = (value) =>
value === UNMEASURED ? undefined : `${value.toFixed(0)}px`,
getA11ValueText = DEFAULT_GET_A11_VALUE_TEXT,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getA11ValueText before was unstable reference

@layershifter layershifter marked this pull request as ready for review August 14, 2024 13:48
@layershifter layershifter merged commit 09e0824 into microsoft:main Aug 14, 2024
3 checks passed
@layershifter layershifter deleted the fix/resize-handle-stable branch August 14, 2024 14:26
george-cz added a commit that referenced this pull request Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants