Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Fix runaway state change loop for showing validation errors in event subscription. #2119

Merged
merged 1 commit into from
Apr 4, 2020
Merged
Changes from all commits
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
15 changes: 8 additions & 7 deletions assets/js/blocks/cart-checkout/checkout/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ const Checkout = ( {
shippingRates = [],
} ) => {
const { isEditor } = useEditorContext();
const { hasOrder, onCheckoutCompleteError } = useCheckoutContext();
const {
hasOrder,
hasError: checkoutHasError,
isComplete: checkoutIsComplete,
} = useCheckoutContext();
const { showAllValidationErrors } = useValidationContext();
const {
shippingRatesLoading,
Expand Down Expand Up @@ -121,14 +125,11 @@ const Checkout = ( {
}, [ shippingAsBilling, setBillingData ] );

useEffect( () => {
const unsubscribeCompleteError = onCheckoutCompleteError( () => {
if ( checkoutIsComplete && checkoutHasError ) {
showAllValidationErrors();
scrollToTop( { focusableSelector: 'input:invalid' } );
} );
return () => {
unsubscribeCompleteError();
};
}, [ onCheckoutCompleteError ] );
}
}, [ checkoutIsComplete, checkoutHasError ] );

if ( ! isEditor && ! hasOrder ) {
return <CheckoutOrderError />;
Expand Down