Vue: Vue cancels <video> unmute if updating DOM

Created on 7 May 2018  Â·  5Comments  Â·  Source: vuejs/vue

Version

2.5.16

Reproduction link

https://codepen.io/evvvritt/pen/BxmOrN

Steps to reproduce

  1. (Ensure browser tab is unmuted and audio is audible)
  2. Click each button several times and observe the effects:
    – Toggle Mute without DOM update properly toggles mute every time
    – Toggle Mute with... both require two clicks to unmute the video

What is expected?

Toggle Mute with DOM update

What is actually happening?

Requires two calls to actually unmute the video


I ran into this trying to toggle a mute icon based on the mute state. I tried v-show, :class, and :data-attr changes – all have the same problem :/

nextTick related

Most helpful comment

@michaelpumo I verified that this is due to 2.5.x queueing updates in a macrotask, which causes iOS Safari to consider the operation no longer directly triggered by the user. This should be fixed in upcoming 2.6 which reverts all updates to microtasks.

All 5 comments

Because you shouldn't be unmuting by directly manipulating the DOM. Instead you should mutate the isMuted state and let Vue do it. Vue is doing its job by making sure your DOM is in sync with your state.

Thanks @yyx990803! I should have mentioned that mutating muted attribute via state doesn't work on iOS11 – it pauses the video. By comparison, you can fluidly un/mute by targeting the

https://codepen.io/evvvritt/pen/pVpyzr

I'm trying to have custom video controls, is there an iOS compatible way to achieve this in Vue that I'm missing?

Related:

2042

New

@evvvritt is right - updating mute/unmute via state works on desktop but not in ios.

I am having this issue also.

If I bind a boolean to a muted prop of the video, it works in desktop Chrome and Firefox but not Safari or Safari on iOS.

If I try to set the video.muted = false on the video via a ref, it doesn't work. Something fishy is certainly going on here.

@michaelpumo I verified that this is due to 2.5.x queueing updates in a macrotask, which causes iOS Safari to consider the operation no longer directly triggered by the user. This should be fixed in upcoming 2.6 which reverts all updates to microtasks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paceband picture paceband  Â·  3Comments

aviggngyv picture aviggngyv  Â·  3Comments

wufeng87 picture wufeng87  Â·  3Comments

loki0609 picture loki0609  Â·  3Comments

loki0609 picture loki0609  Â·  3Comments