diff --git a/packages/js/components/changelog/fix-47791-confetti-pop-every-render b/packages/js/components/changelog/fix-47791-confetti-pop-every-render new file mode 100644 index 00000000000..32b8e814202 --- /dev/null +++ b/packages/js/components/changelog/fix-47791-confetti-pop-every-render @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Added useRef to ensure confetti animation is only run once diff --git a/packages/js/components/src/confetti-animation/index.ts b/packages/js/components/src/confetti-animation/index.ts index 825461354ca..de84ea1cf08 100644 --- a/packages/js/components/src/confetti-animation/index.ts +++ b/packages/js/components/src/confetti-animation/index.ts @@ -2,7 +2,7 @@ * External dependencies */ import confetti from 'canvas-confetti'; -import { useEffect } from '@wordpress/element'; +import { useEffect, useRef } from '@wordpress/element'; /** * Note: This was copied over from https://github.com/Automattic/wp-calypso/blob/a39539547780871d0371a20fcf21c767a86a1010/packages/components/src/confetti/index.ts @@ -83,9 +83,12 @@ export const ConfettiAnimation = ( { delay = 0, colors = COLORS, } ) => { + const hasRun = useRef( false ); + useEffect( () => { - if ( trigger ) { + if ( ! hasRun.current && trigger ) { setTimeout( () => fireConfetti( colors ), delay ); + hasRun.current = true; } }, [ trigger, delay, colors ] ); diff --git a/plugins/woocommerce/changelog/fix-47791-confetti-pop-every-render b/plugins/woocommerce/changelog/fix-47791-confetti-pop-every-render new file mode 100644 index 00000000000..32b8e814202 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-47791-confetti-pop-every-render @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Added useRef to ensure confetti animation is only run once