Skip to content

iOS 13 Safari PWA div clicks only fire erratically #21690

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

Closed
tn-5 opened this issue May 11, 2020 · 7 comments
Closed

iOS 13 Safari PWA div clicks only fire erratically #21690

tn-5 opened this issue May 11, 2020 · 7 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Milestone

Comments

@tn-5
Copy link

tn-5 commented May 11, 2020

When styling a div element as a clickable button in iOS and subsequently installing it as a PWA, the element only erratically responds to click events.

Tested on: iOS 13.4.1

Reproduce

Standard blazorwasm template (with pwa option), add following code to counter.razor:

<div class="bg-primary" @onclick="IncrementCount" style="height:40px;">
    <p>Button 1</p>            
</div>
<br>
<div class="bg-primary" @onclick="IncrementCount" style="height:40px;cursor: pointer;">
    <p>Button 2</p>            
</div>
<br>
<button class="bg-primary" @onclick="IncrementCount" style="height:40px;cursor: pointer;">
    <p>Button 3</p>            
</button>

Results (run from browser)

Clicking on any of the 3 elements result in the counter being in incremented

Results (when installed as a PWA - add to home screen on iPhone)

Only clicking #3 (the button) works reliably, the first two sometimes respond erratically and sometimes not at all.

@tn-5 tn-5 changed the title iOS 13 Safari PWA clicks only fire erratically iOS 13 Safari PWA div clicks only fire erratically May 11, 2020
@pranavkm pranavkm added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-blazor Includes: Blazor, Razor Components and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 11, 2020
@javiercn
Copy link
Member

@tn-5 thanks for contacting us.

Can you provide us with a minimal repro project that demonstrates the issue so that we can help you out?

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label May 12, 2020
@tn-5
Copy link
Author

tn-5 commented May 12, 2020

To reproduce

  1. dotnet new blazorwasm -p
  2. Edit Counter.razor in Pages folder, paste code from initial report just before the @code line

To test this it must be accessible from an iPhone. So either deploy it somewhere or just run it locally, but listen on a port accessible by the iPhone, for example:

  1. dotnet run --urls=http://xxx.xxx.xxx.xxx:5005

where xxx.xxx.xxx.xxx is the PC IP address accessible from the iPhone (on the same wifi network for example).

  1. Open Safari on the test iPhone, enter the url above (5005 is chosen as an arbitrary test port in this case)

  2. Navigate to the counter page (from menu)

  3. Click on "Button 1", 2 and 3 - observe that the counter increments (correctly) each time.

  4. Install the same app as a PWA. With the page open on the iPhone click on the share icon, select "Add to home screen". An icon for the app is added to the home screen.

  5. Open the app from the home screen icon. Repeat the test - navigate to the counter page and click the buttons.

  6. Observe that only the original "Click me" button and "Button 3" responds. Buttons 1 and 2 do not work, or only erratically.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels May 12, 2020
@pranavkm pranavkm added this to the Discussions milestone May 12, 2020
@SteveSandersonMS
Copy link
Member

@tn-5 Sorry for the inconvenience. However, as far as I'm aware, this is not really a Blazor issue, but is rather a quirk of how Safari behaves on iOS in general.

There are many, many other reports of people wondering about this when using other frameworks too (example, or for others, search the web for ios safari onclick). There are also many different workarounds that people propose, such as setting certain <meta> tags on the page, registering top-level onclick or ontouchstart events, and more. I'd recommend you look into the various workarounds that people propose and find one you think is suitable for your app.

In general, Blazor isn't a polyfill library and doesn't try to normalize browser quirks such as this. However if you think there is a specific thing Blazor should do to make this specific thing better we'd definitely be open to considering it.

@SteveSandersonMS SteveSandersonMS added ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels May 13, 2020
@ghost ghost added the Status: Resolved label May 13, 2020
@tn-5
Copy link
Author

tn-5 commented May 13, 2020

I'm aware that Safari mobile (like all browsers) have quirks that you may need to work around. The thing that concerned me in this case it not that it does not work on Safari, but that there is a different between Safari mobile (as a website) and Safari mobile (as a PWA launched from the home screen).

I suppose I was worried that there might be something about the way Blazor specifically registers the onclick events in PWA mode (or how the startup is done) that may affect this.

In any case the workaround for this specific issue is to simply use button elements for clickable items.

@tn-5
Copy link
Author

tn-5 commented May 13, 2020

I've done further testing and I'm thinking it may be a Blazor specific issue.
If you replace @onclick="IncrementCount" in the repo above with onclick="alert('clicked')" the event fires every time.
It is only the processing of the event by Blazor that does not seem to work.

@SteveSandersonMS
Copy link
Member

Blazor uses event delegation - that’s why it’s different and affects all event delegation systems.

@ghost
Copy link

ghost commented May 14, 2020

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed May 14, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jun 13, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

4 participants