Commit 63d2838ff4a for woocommerce

commit 63d2838ff4ab06b821a00095d055b731243f02a9
Author: Mike Jolley <mike.jolley@me.com>
Date:   Thu Nov 26 12:58:23 2026 +0000

    Add motion to address suggestions (#70864)

    * Animate address suggestions and snackbars

    Suggestions slide 4px from the field and fade, and slide back to close.
    Snackbars rise in and drop out, and unmount when the animation ends
    instead of after a fixed timeout. Adds usePresence and whenAnimationsEnd.

    * Keep address suggestions open when results first appear

    When the first results arrive, the observer re-adds the input to apply
    autocomplete=none. The input blurs and focuses again, and the delayed
    blur handler closed the list. Skip the close when the field has focus.

    * Combine the changelog entries into one

    * Add this PR's helpers and lessons to the Motion guide

    * Move snackbar motion to its own PR

    * Clear retained presence content when exit turns off

    If exit switched to false while the value stayed null mid-exit, the hook kept returning the old content as exiting until the animation ended. Clear it during render instead.

    * Keep function and NaN content stable in usePresence

    useState and its setter call a function argument, so function content was called instead of stored, and NaN never equals itself, so both looped until React threw. Wrap the setter values and compare with Object.is.

    * Share the attributes for exiting content

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---------

    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/add-cart-checkout-motion-presence b/plugins/woocommerce/changelog/add-cart-checkout-motion-presence
new file mode 100644
index 00000000000..3f019a4c6fc
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-cart-checkout-motion-presence
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Animate the address suggestions in Checkout as they open and close, and keep them open when the first results appear.
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/address-autocomplete.tsx b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/address-autocomplete.tsx
index 579cb6d4f8b..d92625e9c31 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/address-autocomplete.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/address-autocomplete.tsx
@@ -15,6 +15,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
 import { useEffect, useState, useRef } from '@wordpress/element';
 import { AddressFormType, getSettingWithCoercion } from '@woocommerce/settings';
 import { useCheckoutAddress } from '@woocommerce/base-context';
+import { usePresence } from '@woocommerce/base-hooks';

 /**
  * Internal dependencies
@@ -321,6 +322,10 @@ export const AddressAutocomplete = ( {
 		};
 	}, [] );

+	// Keyboard changes apply immediately, so a list that a key closes does not animate out. Typing sets this back,
+	// because a list that typing opens can close with a click or a blur.
+	const [ isClosedByKey, setIsClosedByKey ] = useState( false );
+
 	const addressChangeHandler = ( value: string ) => {
 		props.onChange( value );

@@ -344,6 +349,7 @@ export const AddressAutocomplete = ( {
 		// inputType or :-webkit-autofill.
 		if ( userIsTypingRef.current ) {
 			setSearchValue( value );
+			setIsClosedByKey( false );
 		}
 	};

@@ -379,6 +385,7 @@ export const AddressAutocomplete = ( {
 						addressType
 					];
 				if ( provider ) {
+					setIsClosedByKey( true );
 					setIsSettingAddress( true );
 					// Immediately suppress search to prevent any change events from triggering search
 					suppressSearchTimeoutRef.current = setTimeout( () => {
@@ -408,8 +415,12 @@ export const AddressAutocomplete = ( {
 				}
 			}
 		} else if ( event.key === 'Escape' ) {
+			setIsClosedByKey( true );
 			setSuggestions( [] );
 			setSelectedSuggestion( -1 );
+		} else if ( event.key === 'Tab' ) {
+			// Tab moves focus away, and the blur closes the list.
+			setIsClosedByKey( true );
 		}
 	};

@@ -447,6 +458,15 @@ export const AddressAutocomplete = ( {
 	const handleBlur = () => {
 		// Use a small delay to allow clicks on suggestions to register
 		setTimeout( () => {
+			// The field blurs and focuses again when the observer above re-adds it, which happens when the first
+			// results arrive. Keep the list open if the field has focus again.
+			const inputElement = inputRef.current?.inputRef?.current;
+			if (
+				inputElement &&
+				inputElement.ownerDocument.activeElement === inputElement
+			) {
+				return;
+			}
 			setSuggestions( [] );
 			setSelectedSuggestion( -1 );
 		}, 200 );
@@ -458,6 +478,12 @@ export const AddressAutocomplete = ( {
 			? `suggestion-item-${ addressType }-${ selectedSuggestion }`
 			: undefined;

+	// The list stays mounted while it slides back to the field.
+	const presence = usePresence(
+		searchValue.length >= 3 && suggestions.length > 0 ? suggestions : null,
+		{ exit: ! isClosedByKey }
+	);
+
 	return (
 		<div className="wc-block-components-address-autocomplete-container">
 			<ValidatedTextInput
@@ -484,13 +510,15 @@ export const AddressAutocomplete = ( {
 					) : null
 				}
 			/>
-			{ searchValue.length >= 3 && suggestions.length > 0 ? (
+			{ presence.value ? (
 				<Suggestions
 					selectedSuggestion={ selectedSuggestion }
-					suggestions={ suggestions }
+					suggestions={ presence.value }
 					branding={ activeProviderBranding }
 					addressType={ addressType }
 					onSuggestionClick={ handleSuggestionClick }
+					isExiting={ presence.isExiting }
+					containerRef={ presence.ref }
 				/>
 			) : null }
 		</div>
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/style.scss
index 7be55df8296..779be3a3f71 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/style.scss
@@ -44,6 +44,30 @@ This file is part of the WooCommerce Blocks autocomplete. If editing shortcode,
 	border-radius: $universal-border-radius;
 	box-sizing: border-box;

+	// The list slides 4px from the field over `lg` and fades in over `md`. It is new on the page, so it starts
+	// from `@starting-style`. All of its motion is a transition, so it turns around if it opens again while it closes.
+	@include motion-transition($state: opacity, $move: translate);
+
+	@starting-style {
+		opacity: 0;
+	}
+
+	@include motion-safe {
+		@starting-style {
+			translate: 0 -4px;
+		}
+	}
+
+	// The list stays mounted until it has slid back to the field. Exits are shorter: it goes over `md`, faster than it came.
+	&[data-wc-exiting] {
+		opacity: 0;
+		@include motion-transition($state: opacity, $move: translate, $duration: md);
+
+		@include motion-safe {
+			translate: 0 -4px;
+		}
+	}
+
 	.suggestions-list {
 		list-style: none;
 		margin: 0;
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/suggestions.tsx b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/suggestions.tsx
index 838f8ef3928..08e3ed04adf 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/suggestions.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/address-autocomplete/suggestions.tsx
@@ -4,6 +4,7 @@
 import { AddressAutocompleteResult } from '@woocommerce/types';
 import { decodeEntities } from '@wordpress/html-entities';
 import { sanitizeHTML } from '@woocommerce/sanitize';
+import { exitingProps } from '@woocommerce/base-hooks';

 /**
  * Get highlighted label parts based on matches returned by `search` results.
@@ -67,12 +68,17 @@ export const Suggestions = ( {
 	selectedSuggestion,
 	addressType,
 	onSuggestionClick,
+	isExiting = false,
+	containerRef,
 }: {
 	suggestions: AddressAutocompleteResult[];
 	branding?: string;
 	selectedSuggestion: number;
 	addressType: string;
 	onSuggestionClick: ( suggestionId: string ) => void;
+	// The list stays mounted while it animates out after it closes.
+	isExiting?: boolean;
+	containerRef?: React.Ref< HTMLDivElement >;
 } ) => {
 	if ( ! suggestions ) {
 		return null;
@@ -82,9 +88,12 @@ export const Suggestions = ( {

 	return (
 		<div
+			ref={ containerRef }
 			className="wc-block-components-address-autocomplete-suggestions"
 			role="region"
 			aria-live="polite"
+			{ ...exitingProps( isExiting ) }
+			{ ...( isExiting && { 'data-wc-exiting': '' } ) }
 		>
 			<ul
 				className="suggestions-list"
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/hooks/index.js b/plugins/woocommerce/client/blocks/assets/js/base/hooks/index.js
index d61f3ea4d05..ceaf1ec9a8a 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/hooks/index.js
+++ b/plugins/woocommerce/client/blocks/assets/js/base/hooks/index.js
@@ -12,3 +12,4 @@ export * from './use-observed-viewport';
 export * from './use-schema-parser';
 export * from './use-query-loop-product-context-validation';
 export * from './use-preview-mode';
+export * from './use-presence';
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/hooks/test/use-presence.ts b/plugins/woocommerce/client/blocks/assets/js/base/hooks/test/use-presence.ts
new file mode 100644
index 00000000000..1fdeff7ea0c
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/base/hooks/test/use-presence.ts
@@ -0,0 +1,129 @@
+/**
+ * External dependencies
+ */
+import { act, renderHook } from '@testing-library/react';
+
+/**
+ * Internal dependencies
+ */
+import { usePresence } from '../use-presence';
+
+type Props = { value: string[] | null; exit?: boolean };
+
+const renderUsePresence = ( initialProps: Props ) =>
+	renderHook(
+		( { value, exit = true }: Props ) => usePresence( value, { exit } ),
+		{ initialProps }
+	);
+
+// An element with one running animation. Like a browser animation, it reports `finished` once `finish` is called.
+const createAnimatingElement = () => {
+	let resolveFinished = () => undefined as void;
+	const animation = {
+		playState: 'running',
+		finished: new Promise< void >( ( resolve ) => {
+			resolveFinished = resolve;
+		} ),
+		effect: { getComputedTiming: () => ( { endTime: 200 } ) },
+	};
+	const element = document.createElement( 'div' );
+	element.getAnimations = () => [ animation as unknown as Animation ];
+	const finish = () => {
+		animation.playState = 'finished';
+		resolveFinished();
+	};
+	return { element, finish };
+};
+
+describe( 'usePresence', () => {
+	const open = [ 'a', 'b' ];
+
+	it( 'shows the value while it is present', () => {
+		const { result } = renderUsePresence( { value: open } );
+
+		expect( result.current.value ).toBe( open );
+		expect( result.current.isExiting ).toBe( false );
+	} );
+
+	it( 'removes the value immediately when nothing animates', () => {
+		const { result, rerender } = renderUsePresence( { value: open } );
+
+		rerender( { value: null } );
+		expect( result.current.value ).toBeNull();
+		expect( result.current.isExiting ).toBe( false );
+	} );
+
+	it( 'keeps the last value while the element animates out', async () => {
+		const { result, rerender } = renderUsePresence( { value: open } );
+		const { element, finish } = createAnimatingElement();
+		result.current.ref.current = element;
+
+		rerender( { value: null } );
+		expect( result.current.value ).toBe( open );
+		expect( result.current.isExiting ).toBe( true );
+
+		await act( async () => finish() );
+		expect( result.current.value ).toBeNull();
+		expect( result.current.isExiting ).toBe( false );
+	} );
+
+	it( 'turns around when a value arrives during the exit', async () => {
+		const { result, rerender } = renderUsePresence( { value: open } );
+		const { element, finish } = createAnimatingElement();
+		result.current.ref.current = element;
+		const reopened = [ 'c' ];
+
+		rerender( { value: null } );
+		rerender( { value: reopened } );
+		expect( result.current.value ).toBe( reopened );
+		expect( result.current.isExiting ).toBe( false );
+
+		// The cancelled exit must not remove the new value.
+		await act( async () => finish() );
+		expect( result.current.value ).toBe( reopened );
+	} );
+
+	it( 'removes the value immediately when exit is false', () => {
+		const { result, rerender } = renderUsePresence( { value: open } );
+		result.current.ref.current = createAnimatingElement().element;
+
+		rerender( { value: null, exit: false } );
+		expect( result.current.value ).toBeNull();
+		expect( result.current.isExiting ).toBe( false );
+	} );
+
+	it( 'removes an exiting value when exit turns false', () => {
+		const { result, rerender } = renderUsePresence( { value: open } );
+		result.current.ref.current = createAnimatingElement().element;
+
+		rerender( { value: null } );
+		expect( result.current.isExiting ).toBe( true );
+
+		rerender( { value: null, exit: false } );
+		expect( result.current.value ).toBeNull();
+		expect( result.current.isExiting ).toBe( false );
+	} );
+
+	it( 'keeps content that is a function without calling it', () => {
+		const renderContent = jest.fn( () => 'content' );
+		const { result, rerender } = renderHook(
+			( { value }: { value: ( () => string ) | null } ) =>
+				usePresence( value ),
+			{ initialProps: { value: null as ( () => string ) | null } }
+		);
+		result.current.ref.current = createAnimatingElement().element;
+
+		rerender( { value: renderContent } );
+		expect( result.current.value ).toBe( renderContent );
+
+		rerender( { value: null } );
+		expect( result.current.value ).toBe( renderContent );
+		expect( result.current.isExiting ).toBe( true );
+		expect( renderContent ).not.toHaveBeenCalled();
+	} );
+
+	it( 'settles when the content is NaN', () => {
+		const { result } = renderHook( () => usePresence( NaN ) );
+		expect( result.current.value ).toBeNaN();
+	} );
+} );
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/hooks/use-presence.ts b/plugins/woocommerce/client/blocks/assets/js/base/hooks/use-presence.ts
new file mode 100644
index 00000000000..8b41698d006
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/base/hooks/use-presence.ts
@@ -0,0 +1,64 @@
+/**
+ * External dependencies
+ */
+import { useLayoutEffect, useRef, useState } from '@wordpress/element';
+import { whenAnimationsEnd } from '@woocommerce/base-utils';
+
+/**
+ * Keeps content mounted while it animates out, such as a dropdown that closes.
+ *
+ * Pass the content to show, or `null` to remove it. When it becomes `null`, the hook keeps returning the last content
+ * with `isExiting` set, until the animations of `ref` end. Style the exit on `isExiting`. If new content arrives first,
+ * `isExiting` is unset again, so a transition turns around from its current position. Nothing is kept when nothing
+ * animates, such as in Jest.
+ *
+ * @param value        The content to show, or `null` when there is none.
+ * @param options
+ * @param options.exit Set to `false` to remove the content immediately, for example after a key press.
+ * @return The content to render, whether it is exiting, and the ref for the element that animates.
+ */
+export function usePresence< T, E extends Element = HTMLDivElement >(
+	value: T | null,
+	{ exit = true }: { exit?: boolean } = {}
+) {
+	const ref = useRef< E | null >( null );
+	// The state setters wrap the content, so that content that is a function is stored, not called.
+	const [ previousValue, setPreviousValue ] = useState( () => value );
+	const [ exitingValue, setExitingValue ] = useState< T | null >( null );
+
+	// Adjust state while rendering, so the exiting content never unmounts for a frame. Turning `exit` off mid-exit
+	// removes the content at once.
+	if (
+		! Object.is( value, previousValue ) ||
+		( ! exit && exitingValue !== null )
+	) {
+		setPreviousValue( () => value );
+		setExitingValue( () =>
+			value === null && exit ? previousValue : null
+		);
+	}
+
+	// A layout effect runs after the exit style is in the DOM, so its transitions have started, and before paint, so
+	// content that does not animate is removed without a visible frame.
+	useLayoutEffect( () => {
+		if ( exitingValue === null ) {
+			return;
+		}
+		return whenAnimationsEnd( ref.current, () => setExitingValue( null ) );
+	}, [ exitingValue ] );
+
+	return {
+		value: value ?? exitingValue,
+		isExiting: value === null && exitingValue !== null,
+		ref,
+	};
+}
+
+/**
+ * Attributes for content that is exiting. It is already gone for the shopper, so it must not take clicks or be read
+ * out. React 18 has no `inert` prop, so spread these on the element.
+ *
+ * @param isExiting Whether the content is exiting.
+ */
+export const exitingProps = ( isExiting: boolean ) =>
+	isExiting ? { inert: '', 'aria-hidden': true } : {};
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/utils/index.js b/plugins/woocommerce/client/blocks/assets/js/base/utils/index.js
index d2a62193041..b49bfdba340 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/utils/index.js
+++ b/plugins/woocommerce/client/blocks/assets/js/base/utils/index.js
@@ -18,3 +18,4 @@ export * from './keyby';
 export * from './pick';
 export * from './get-inline-styles';
 export * from './use-return-focus';
+export * from './when-animations-end';
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/utils/test/when-animations-end.ts b/plugins/woocommerce/client/blocks/assets/js/base/utils/test/when-animations-end.ts
new file mode 100644
index 00000000000..c99a4fd1707
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/base/utils/test/when-animations-end.ts
@@ -0,0 +1,127 @@
+/**
+ * Internal dependencies
+ */
+import { whenAnimationsEnd } from '../when-animations-end';
+
+// Jest has no Web Animations API. Like a browser animation, this fake reports `finished` or `idle` when it ends.
+const createAnimation = (
+	playState: Animation[ 'playState' ] = 'running',
+	endTime = 200
+) => {
+	let resolveFinished = () => undefined as void;
+	let rejectFinished = () => undefined as void;
+	const animation = {
+		playState,
+		finished: new Promise< void >( ( resolve, reject ) => {
+			resolveFinished = resolve;
+			rejectFinished = () => reject( new Error( 'AbortError' ) );
+		} ),
+		effect: { getComputedTiming: () => ( { endTime } ) },
+	};
+	return {
+		animation: animation as unknown as Animation,
+		finish: () => {
+			animation.playState = 'finished';
+			resolveFinished();
+		},
+		cancel: () => {
+			animation.playState = 'idle';
+			rejectFinished();
+		},
+	};
+};
+
+// The element returns the animations in the array when it is asked, so a test can add one later.
+const createElement = ( animations: Animation[] ) => {
+	const element = document.createElement( 'div' );
+	element.getAnimations = () => animations;
+	return element;
+};
+
+// Lets promise callbacks run.
+const flushPromises = () => new Promise( ( resolve ) => setTimeout( resolve ) );
+
+describe( 'whenAnimationsEnd', () => {
+	it( 'calls back immediately when the browser has no Web Animations API', () => {
+		const callback = jest.fn();
+		whenAnimationsEnd( document.createElement( 'div' ), callback );
+		expect( callback ).toHaveBeenCalledTimes( 1 );
+	} );
+
+	it( 'calls back immediately when there is no element', () => {
+		const callback = jest.fn();
+		whenAnimationsEnd( null, callback );
+		expect( callback ).toHaveBeenCalledTimes( 1 );
+	} );
+
+	it( 'calls back immediately when no animation is in progress', () => {
+		const callback = jest.fn();
+		const element = createElement( [
+			createAnimation( 'finished' ).animation,
+			createAnimation( 'idle' ).animation,
+			createAnimation( 'running', Infinity ).animation,
+		] );
+		whenAnimationsEnd( element, callback );
+		expect( callback ).toHaveBeenCalledTimes( 1 );
+	} );
+
+	it( 'waits for every running and paused animation to end', async () => {
+		const callback = jest.fn();
+		const running = createAnimation( 'running' );
+		const paused = createAnimation( 'paused' );
+		whenAnimationsEnd(
+			createElement( [ running.animation, paused.animation ] ),
+			callback
+		);
+
+		running.finish();
+		await flushPromises();
+		expect( callback ).not.toHaveBeenCalled();
+
+		paused.finish();
+		await flushPromises();
+		expect( callback ).toHaveBeenCalledTimes( 1 );
+	} );
+
+	it( 'treats a cancelled animation as ended', async () => {
+		const callback = jest.fn();
+		const animation = createAnimation();
+		whenAnimationsEnd( createElement( [ animation.animation ] ), callback );
+
+		animation.cancel();
+		await flushPromises();
+		expect( callback ).toHaveBeenCalledTimes( 1 );
+	} );
+
+	it( 'waits again for a transition that turns around', async () => {
+		const callback = jest.fn();
+		const first = createAnimation();
+		const reversed = createAnimation();
+		const animations = [ first.animation ];
+		whenAnimationsEnd( createElement( animations ), callback );
+
+		// A transition that turns around cancels the old transition and starts a new one.
+		animations.push( reversed.animation );
+		first.cancel();
+		await flushPromises();
+		expect( callback ).not.toHaveBeenCalled();
+
+		reversed.finish();
+		await flushPromises();
+		expect( callback ).toHaveBeenCalledTimes( 1 );
+	} );
+
+	it( 'does not call back after it is cancelled', async () => {
+		const callback = jest.fn();
+		const animation = createAnimation();
+		const cancel = whenAnimationsEnd(
+			createElement( [ animation.animation ] ),
+			callback
+		);
+
+		cancel();
+		animation.finish();
+		await flushPromises();
+		expect( callback ).not.toHaveBeenCalled();
+	} );
+} );
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/utils/when-animations-end.ts b/plugins/woocommerce/client/blocks/assets/js/base/utils/when-animations-end.ts
new file mode 100644
index 00000000000..a60c4857ffb
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/base/utils/when-animations-end.ts
@@ -0,0 +1,54 @@
+/**
+ * Calls `callback` when the CSS transitions and animations of `element` end, so that a script can wait for motion
+ * instead of a fixed timeout. The callback runs immediately when nothing animates, such as in Jest, which has no Web
+ * Animations API.
+ *
+ * Call it after the style change that starts the motion. If a transition turns around while the script waits, the
+ * script waits for the new one too.
+ *
+ * @param element  The element that animates.
+ * @param callback Runs one time, when no animation of the element is in progress.
+ * @return A function that cancels the callback.
+ */
+export const whenAnimationsEnd = (
+	element: Element | null | undefined,
+	callback: () => void
+): ( () => void ) => {
+	let isCancelled = false;
+
+	const waitForAnimations = () => {
+		if ( isCancelled ) {
+			return;
+		}
+		// Only animations with `playState` `running` or `paused` are in progress. A finished animation can still hold
+		// its end state, and a cancelled one never ends, so neither must hold back the callback. A loop never ends.
+		const animations =
+			typeof element?.getAnimations === 'function'
+				? element
+						.getAnimations()
+						.filter(
+							( animation ) =>
+								( animation.playState === 'running' ||
+									animation.playState === 'paused' ) &&
+								animation.effect?.getComputedTiming()
+									.endTime !== Infinity
+						)
+				: [];
+		if ( animations.length === 0 ) {
+			callback();
+			return;
+		}
+		// A cancelled animation rejects `finished`. It no longer animates, so it counts as ended.
+		void Promise.all(
+			animations.map( ( animation ) =>
+				animation.finished.catch( () => undefined )
+			)
+		).then( waitForAnimations );
+	};
+
+	waitForAnimations();
+
+	return () => {
+		isCancelled = true;
+	};
+};
diff --git a/plugins/woocommerce/client/blocks/docs/contributors/motion.md b/plugins/woocommerce/client/blocks/docs/contributors/motion.md
index a2b69e90513..5a2600994d5 100644
--- a/plugins/woocommerce/client/blocks/docs/contributors/motion.md
+++ b/plugins/woocommerce/client/blocks/docs/contributors/motion.md
@@ -86,7 +86,12 @@ Use the helpers in `assets/css/abstracts/_motion.scss`. Do not write `transition

 Use `@starting-style` with transitions for an element that is new on the page, such as a dropdown. Then all of its motion is a transition, and a transition turns around by itself.

-Motion that changes the layout runs in JavaScript, because it must measure sizes. JavaScript helpers end immediately when nothing animates, and in Jest. This section lists the JavaScript helpers when they are added.
+Motion that changes the layout runs in JavaScript, because it must measure sizes. JavaScript helpers end immediately when nothing animates, and in Jest.
+
+| Helper | Use |
+|--------|-----|
+| `whenAnimationsEnd( element, callback )` (`@woocommerce/base-utils`) | Runs `callback` when the animations of `element` end, instead of after a fixed timeout. It waits again if a transition turns around. It returns a function that cancels the callback. |
+| `usePresence( value, { exit } )` (`@woocommerce/base-hooks`) | Keeps content mounted while it animates out. Pass the content, or `null` to remove it. It returns `{ value, isExiting, ref }`. Put `ref` on the element that animates. Pass `exit: false` to remove the content immediately, for example after a key press. |

 ## Techniques