question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preact indirectly trigger a video pause

See original GitHub issue

Hi,

I came across a quite intriguing issue that I assume is related to the DOM mutations strategy that preact is using.

When rendering the following component with preact:

class Player extends Component {
    state = { show: true }

    componentDidMount() {
        document.onclick = () => {
            this.setState({ show: false })
        }
    }

    render() {
        return (
            <div>
                { null }
                { this.state.show && <div></div> }
                { null }
                <video
                    autoplay="true"
                    src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
                    style={ {width:'400px',height:'300px'} }
                />
            </div>
        );
    }
}

I observed that on state change (when clicking on the document), the video playback is being paused. After reproducing in a minimal example and comparing with React I can say that this issue is only reproducible with preact.

Here is a repo of a demo showing the issue: https://github.com/happypoulp/preact-video-issue

The structure of the elements in the render function above may seems peculiar but the issue does not seem to exist when using another structure (like removing one of the { null } or changing the <video> position).

I have no idea about why a change in the DOM may cause a video to be paused but since this issue is reproducible 100% of time, I guess that someone more familiar with the rendering strategy of preact may have a good explanation for it.

I have found various ways to avoid this issue (by changing the structure or by moving out the video tag out of the render function) so it’s not really critical but I’d really like to understand what’s happening here.

Issue reproduced with preact ^8.1.0, on Chrome 58.0.3029.110.

Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
yaodingydcommented, Mar 6, 2018

@vedam Your issue is actually different from OP’s. Preact caches components and their DOM elements, so when the first time video route loads, it works fine; next time it loads, it’s the cached element, and “Video pausing on DOM move/unmount is straight Google Chrome bug”. I think React doesn’t cache components, so every time video loads, it’s a new component, and it autoplays fine.

Unfortunately, there is nothing much to do unless we expose one option to disable component caching.

2reactions
developitcommented, Jul 11, 2017

Yup, it would have been getting moved within its parent. I’m just working to push 8.2.0 out right now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to play/pause video in React without external library?
I have a video tag () in my webpage, and a "play/pause" button that when the user clicks on it, the video starts/stops...
Read more >
Pause-and-Play: Automatically Linking Screencast Video ...
Figure 1: Pause-and-Play links the target application with the progress-aware video player. The video player automatically pauses when the user lags behind the....
Read more >
least expensive way to watch fox news
Least Expensive Way To Watch Fox NewsIf you want to watch FOX live the best way is with an antenna. Compare hotel deals,...
Read more >
How to control video lesson playback - quick guide
Press your Space bar to start playing the video. 5. Press the space bar to pause the video. Pressing the space bar repeatedly...
Read more >
Why is the Play/Pause icon appended on the video ... - Support
By default, Outlook displays the Play/Pause icon over the video thumbnail. Please check the below GIF behavior inside Outlook: · Animated GIFs ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found