Skip to content
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

onMouseDown causes splash on real ios browsers #12717

Open
huhaixiao opened this issue Apr 29, 2018 · 9 comments
Open

onMouseDown causes splash on real ios browsers #12717

huhaixiao opened this issue Apr 29, 2018 · 9 comments

Comments

@huhaixiao
Copy link

Do you want to request a feature or report a bug?

bug

What is the current behavior?

unexpected grey splash caused by onMouseDown on real ios device's browsers, both safari and chrome.
Please checkout this grey splash issue first
I did some trial later, and find out that vanilla html <button onmousedown="">btn</button> doesn't cause grey splash, but with React's jsx <button onMouseDown={()=>{}}></button>, there is a noticeable grey splash

What is the expected behavior?

who wants a splash?

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

"react": "^16.3.2"

@gaearon
Copy link
Collaborator

gaearon commented Aug 2, 2018

Can you create a reproducible example?

@gaearon
Copy link
Collaborator

gaearon commented Aug 6, 2018

For future reference, the reproducing example is this:

import React from "react";
import ReactDOM from "react-dom";

function Index() {
  return <button onMouseDown={() => {}}>Wtf</button>;
}

ReactDOM.render(<Index />, document.querySelector("#root"));

https://codesandbox.io/s/p3npm3o6j7

The splashes the author is referring to occur not when you click on the button, but when you click on the body itself several times in a quick succession.

@gaearon
Copy link
Collaborator

gaearon commented Aug 6, 2018

The problem is not specific to React; this also reproduces it:

document.body.addEventListener(
  "mousedown",
  function() {}
);

@gaearon
Copy link
Collaborator

gaearon commented Aug 6, 2018

Hmm.. there was clearly some issue with how I was testing this. It appears that CodeSandbox preview mode is buggy. I'll need to look at it again — for now previous conclusions might be wrong.

@gaearon
Copy link
Collaborator

gaearon commented Aug 6, 2018

Okay, testing this in CodeSandbox was really confusing because of some other code it bundles in.
I think I got to a minimal repro though:

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
</body>
<script>
  var btn = document.createElement("button");
  btn.innerText = "hi";
  document.body.appendChild(btn);
  document.addEventListener('mousedown', (e) => {
    if (e.target === btn) {
      alert('hi');
    }
  });
</script>
</html>

There are two things that "fix" it:

  1. If I remove <!DOCTYPE html> in the beginning, the flash is gone
  2. If I change document.addEventListener to document.body.addEventListener (or get even more specific), the flash is also gone

It seems like the proper solution to this will be #2043. In the meantime, you can probably work around it by not adding mouse event listeners on touch devices (and instead using touch event listeners). Sorry about that!

@philipp-spiess
Copy link
Contributor

This seems to be the minimal example to reproduce this issue. What's strange about this:

  1. This happens whenever a click-ish (both mousedown and click seem to work) is attached to the document.
  2. If I add the following CSS * { -webkit-tap-highlight-color: red; }, the tap will still be grey, even though a button might turn red.
  3. Zooming in will also make this disappear.
  4. Removing <!DOCTYPE html> does fix it as well. (as @gaearon pointed out earlier).

You can try it out without the CodeSandbox chrome using this URL: https://yjy8j5v5rz.codesandbox.io/

I'm downloading a few older iOS versions now to see when this was added.

@philipp-spiess
Copy link
Contributor

@gaearon You beat me to it 😬

Here's another workaround I found 🤔 :

html, body {
  width: 100%;
  height: 100%;
}

@philipp-spiess
Copy link
Contributor

I don't think that #2043 would be a fix for this issue. If you mount your React app into a container that is big enough to fill the whole screen (which most React apps probably are) and then add the click listener to that container, the same issue persists: https://codesandbox.io/s/o4x23pr8m6

What's different with the non-document listeners though:

  1. The behavior is always reproducible, no matter if we add <!DOCTYPE html> or not.
  2. We can use -webkit-tap-highlight-color: transparent; to remove it.

I've filed a WebKit issue for the behavior we're seeing with document as it seems very inconsistent: https://bugs.webkit.org/show_bug.cgi?id=188362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants