-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File: Remove unnecessary synchronization effect #57585
Conversation
Size Change: -41 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
One thing to note is that the fileId
is updated in the following scenario. This does not happen with trunk.
- Insert file block
- Upload file (
fileId
is updated based on the current blockclientId
) - Save the post and reload the browser (block
clientId
will change) - Upload another file
fileId
is updated
If we want to maintain the existing fileId
, we may be able to do it as follows.
diff --git a/packages/block-library/src/file/edit.js b/packages/block-library/src/file/edit.js
index 528a488039..6b24565bdf 100644
--- a/packages/block-library/src/file/edit.js
+++ b/packages/block-library/src/file/edit.js
@@ -64,6 +64,7 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
const {
id,
fileName,
+ fileId,
href,
textLinkHref,
textLinkTarget,
@@ -120,7 +121,7 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
id: newMedia.id,
displayPreview: isPdf ? true : undefined,
previewHeight: isPdf ? 600 : undefined,
- fileId: `wp-block-file--media-${ clientId }`,
+ fileId: fileId || `wp-block-file--media-${ clientId }`,
} );
}
However, since fileId is just a string needed for accessibility (id
, aria-describedby
), there may be no problem even if it is rewritten to upload the file 🤔
@t-hamano, right. The sting just needs to be set when there is a file. It's "safer" to update during every file selection. |
What?
PR removes an unnecessary side-effect for setting the
fileId
attribute.Why?
A similar synchronization effect should be a last resort when there's no clear event responsible for attribute creation. In this case, it can be absorbed by the
onSelectFile
event.Testing Instructions
fileId
attribute is correctly set.Testing Instructions for Keyboard
Same