From d4674c7acc7cb3fe66956e69310d8c050e8572b6 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 17 Sep 2021 06:12:13 +0000 Subject: [PATCH] MediaReplaceFlow: Avoid React warning when selecting media (#34618) * MediaReplaceFlow: Avoid React warning when selecting media * Add inline comment --- .../block-editor/src/components/media-replace-flow/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/media-replace-flow/index.js b/packages/block-editor/src/components/media-replace-flow/index.js index 12e33c12f2d708..57d6c1c3713223 100644 --- a/packages/block-editor/src/components/media-replace-flow/index.js +++ b/packages/block-editor/src/components/media-replace-flow/index.js @@ -77,8 +77,9 @@ const MediaReplaceFlow = ( { }; const selectMedia = ( media ) => { - onSelect( media ); setMediaURLValue( media.url ); + // Calling `onSelect` after the state update since it might unmount the component. + onSelect( media ); speak( __( 'The media file has been replaced' ) ); removeNotice( errorNoticeID ); };