Skip to content

Conversation

@sathyapulse
Copy link
Contributor

@sathyapulse sathyapulse commented Dec 6, 2021

Description

The File drops intercept HTML drops, and it takes precedence with the recent Windows chrome version. It causes the plugins relying on the HTML drop to stop working. Changing the order of the checks fixes the problem — Fixes #36824.

How has this been tested?

The steps to test has been documented in issue #36824.

Screenshots

Types of changes

Changing the order of the checks fixes the problem.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

The File drops intercept HTML drops, and it takes precedence with the recent Windows chrome version. Changing the order of the checks fixes the problem.
@sathyapulse sathyapulse requested a review from ellatrix as a code owner December 6, 2021 14:28
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Dec 6, 2021
@github-actions
Copy link

github-actions bot commented Dec 6, 2021

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @sathyapulse! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t mind switching the order of the conditions, but it’s important to understand what has changed. If getFilesFromDataTransfer isn’t coming back empty, what is it returning? Are there values needing pruning, or is our function not up to spec?

@sathyapulse
Copy link
Contributor Author

I don’t mind switching the order of the conditions, but it’s important to understand what has changed. If getFilesFromDataTransfer isn’t coming back empty, what is it returning? Are there values needing pruning, or is our function not up to spec?

The function getFilesFromDataTransfer returns the file object and is uploaded to the media library using the blob without the fix. The HTML drops aren't captured on Windows Chrome.

The DropZone has been rewritten without a provider recently here, and it changed the code significantly. I'm not sure if that's a regression from the rewrite.

@mcsf
Copy link
Contributor

mcsf commented Dec 6, 2021

The function getFilesFromDataTransfer returns the file object and is uploaded to the media library using the blob without the fix. The HTML drops aren't captured on Windows Chrome.

Do you mean that, when the dragged HTML object contains an image, newer versions of browsers are being smart about it and attaching a File data-transfer item alongside the HTML item? If so, then the fix makes sense.

Copy link
Member

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I do vaguely remember Windows attaching an image version of copied text or html (which is a bit weird), so reordering makes sense.

if ( files.length ) {
_onFilesDrop( files );
} else if ( html ) {
if ( html ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just add a comment here about why the order is important and what this extra image in Windows is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix Sure, I will add a comment. Do we need to change the order here as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that would be good if a manual test reveals a problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix: should the two handlers be only defined once?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sathyapulse: I agree with Ella. Once you have fixed the order in the other handler, and added comments to each to justify the issue (possibly linking to this PR), let us know and we can merge this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @mcsf and @ellatrix.

I've added the fix in the other handler and added comments here. Could you please review it?

@sathyapulse
Copy link
Contributor Author

that, when the dragged HTML object contains an image, newer versions of browsers are being smart about it and attaching a File data-tra

@mcsf Yes, the newer browser version on Windows treats it as a file blob object and attaches/uploads the file to the media library and adds an image block. I did some tests to confirm the browser implementation.

On Mac Chrome 96, the file object is empty, and WP adds the HTML with an external link.
On Windows Chrome 96, the file object returns the blob, and WP uploads the image to the media library.

The file object is empty when the chrome browser is downgraded to version 95 on Windows.

CC: @ellatrix

if ( files.length ) {
_onFilesDrop( files );
} else if ( html ) {
if ( html ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sathyapulse: I agree with Ella. Once you have fixed the order in the other handler, and added comments to each to justify the issue (possibly linking to this PR), let us know and we can merge this.

@mcsf mcsf merged commit b9ea0e3 into WordPress:trunk Dec 8, 2021
@github-actions github-actions bot added this to the Gutenberg 12.2 milestone Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DropZone component listeners not working on latest Chromium browser update

3 participants