From b983444eb197c6ca4324be9c3b1a87b62bf4358e Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Sat, 6 Jan 2024 11:21:21 +0400 Subject: [PATCH] File: Remove unnecessary synchronization effect (#57585) --- packages/block-library/src/file/edit.js | 35 ++++++++++--------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/packages/block-library/src/file/edit.js b/packages/block-library/src/file/edit.js index 20c747de2de988..528a488039acfd 100644 --- a/packages/block-library/src/file/edit.js +++ b/packages/block-library/src/file/edit.js @@ -63,7 +63,6 @@ function ClipboardToolbarButton( { text, disabled } ) { function FileEdit( { attributes, isSelected, setAttributes, clientId } ) { const { id, - fileId, fileName, href, textLinkHref, @@ -85,8 +84,7 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) { ); const { createErrorNotice } = useDispatch( noticesStore ); - const { toggleSelection, __unstableMarkNextChangeAsNotPersistent } = - useDispatch( blockEditorStore ); + const { toggleSelection } = useDispatch( blockEditorStore ); useEffect( () => { // Upload a file drag-and-dropped into the editor. @@ -109,26 +107,21 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) { } }, [] ); - useEffect( () => { - if ( ! fileId && href ) { - // Add a unique fileId to each file block. - __unstableMarkNextChangeAsNotPersistent(); - setAttributes( { fileId: `wp-block-file--media-${ clientId }` } ); - } - }, [ href, fileId, clientId ] ); - function onSelectFile( newMedia ) { - if ( newMedia && newMedia.url ) { - const isPdf = newMedia.url.endsWith( '.pdf' ); - setAttributes( { - href: newMedia.url, - fileName: newMedia.title, - textLinkHref: newMedia.url, - id: newMedia.id, - displayPreview: isPdf ? true : undefined, - previewHeight: isPdf ? 600 : undefined, - } ); + if ( ! newMedia || ! newMedia.url ) { + return; } + + const isPdf = newMedia.url.endsWith( '.pdf' ); + setAttributes( { + href: newMedia.url, + fileName: newMedia.title, + textLinkHref: newMedia.url, + id: newMedia.id, + displayPreview: isPdf ? true : undefined, + previewHeight: isPdf ? 600 : undefined, + fileId: `wp-block-file--media-${ clientId }`, + } ); } function onUploadError( message ) {