-
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 block: Handle drag-and-drop errors #8066
Conversation
Handle any errors that occur when a File block is created via a files transform. That is, when a file is drag-and-dropped into the editor.
@@ -59,6 +61,10 @@ class FileEdit extends Component { | |||
allowedType: '*', | |||
filesList: [ file ], | |||
onFileChange: ( [ media ] ) => this.onSelectFile( media ), | |||
onError: ( message ) => { | |||
this.setState( { hasError: true } ); |
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.
I had to use local state here instead of setAttributes( { href: undefined } )
because we don't support calling setAttributes()
in componentDidMount
.
(Also, we probably shouldn't be using attributes for this anyway—see #3553.)
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.
Looks good. 👍
I did wonder if isMatch
could be used to disallow the transform, but I think showing an appropriate error and the behaviour being similar to when using the MediaPlaceholder are benefits to this approach.
Actually - I did spot an issue. Not caused by this, but related. If you drag an unsupported file type, then update the post and refresh you see a message that the block has encountered an error. Looks like the blob is revoked but the href is still set as an attribute, so it goes through the whole editorMediaUpload call again when mounting, but fails: I can create it as a separate issue if you want to get this PR merged. (edit, issue here #8155) |
Good spotting! There's a whole lot of bugs that exist because we store blob URLs in blocks attributes. We definitely should move away from doing this. #8119 was created as an umbrella issue for this. |
Yeah, totally. I experimented with not allowing the drag-and-drop at all if it's an invalid transform, but decided against it because it makes it feel like the browser is not responsive. |
Description
Fixes #8025.
Handle any errors that occur when a File block is created via a
files
transform. That is, when a file is drag-and-dropped into the editor.How has this been tested?
.js
,.diff
,.json
,.exe
) into the editor.zip
,.pdf
) into the editorScreenshots