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

Commit ea3347b

Browse files
authored
fix possible memory leak (#4524)
1 parent 5f3d26a commit ea3347b

File tree

1 file changed

+5
-1
lines changed
  • assets/js/blocks/cart-checkout/checkout-i2

1 file changed

+5
-1
lines changed

assets/js/blocks/cart-checkout/checkout-i2/block.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,19 @@ const ScrollOnError = ( {
118118
( hasValidationErrors || hasNoticesOfType( 'default' ) );
119119

120120
useEffect( () => {
121+
let scrollToTopTimeout: number;
121122
if ( hasErrorsToDisplay ) {
122123
showAllValidationErrors();
123124
// Scroll after a short timeout to allow a re-render. This will allow focusableSelector to match updated components.
124-
setTimeout( () => {
125+
scrollToTopTimeout = window.setTimeout( () => {
125126
scrollToTop( {
126127
focusableSelector: 'input:invalid, .has-error input',
127128
} );
128129
}, 50 );
129130
}
131+
return () => {
132+
clearTimeout( scrollToTopTimeout );
133+
};
130134
}, [ hasErrorsToDisplay, scrollToTop, showAllValidationErrors ] );
131135

132136
return null;

0 commit comments

Comments
 (0)