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(explore): verified props is not updated #31008

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ export default function withAsyncVerification({
} = props;
const otherPropsRef = useRef(restProps);
const [verifiedProps, setVerifiedProps] = useState({});
const verifiedPropsRef = useRef(verifiedProps);
Copy link
Member

Choose a reason for hiding this comment

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

Can't we remove verifiedProps state and just use verifiedPropsRef?

Copy link
Member Author

Choose a reason for hiding this comment

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

verifiedProps is necessary for rendering a new options list through setVerifiedProps.
I have an idea that this part can be handled using useEffectEvent without utilizing additional ref access.

const [isLoading, setIsLoading] = useState<boolean>(initialIsLoading);
const { addWarningToast } = restProps.actions;

// memoize `restProps`, so that verification only triggers when material
// props are actually updated.
let otherProps = otherPropsRef.current;
verifiedPropsRef.current = verifiedProps;
if (hasUpdates(otherProps, restProps)) {
otherProps = otherPropsRef.current = restProps;
}
Expand Down Expand Up @@ -175,7 +177,10 @@ export default function withAsyncVerification({
if (showLoadingState) {
setIsLoading(false);
}
if (updatedProps && hasUpdates(otherProps, updatedProps)) {
if (
updatedProps &&
hasUpdates(otherProps, verifiedPropsRef.current)
) {
setVerifiedProps({
// save isLoading in combination with other props to avoid
// rendering twice.
Expand Down
Loading