Skip to content

Commit 2485237

Browse files
committed
fix: ensure video elements autoplay in safari
1 parent 6a2c28c commit 2485237

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.changeset/empty-hairs-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure video elements autoplay in safari

packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ export function RegularElement(node, context) {
6161

6262
const is_custom_element = is_custom_element_node(node);
6363

64-
if (is_custom_element) {
64+
if (node.name === 'video' || is_custom_element) {
6565
// cloneNode is faster, but it does not instantiate the underlying class of the
6666
// custom element until the template is connected to the dom, which would
6767
// cause problems when setting properties on the custom element.
6868
// Therefore we need to use importNode instead, which doesn't have this caveat.
69+
// Additionally, Webkit browsers need importNode for video elements for autoplay
70+
// to work correctly.
6971
context.state.metadata.context.template_needs_import_node = true;
7072
}
7173

0 commit comments

Comments
 (0)