Skip to content

Commit 17cb462

Browse files
trueadmbenmccanndummdidumm
authored
fix: ensure muted DOM property works correctly in FF (#13751)
Co-authored-by: Ben McCann <[email protected]> Co-authored-by: Simon H <[email protected]>
1 parent 185e112 commit 17cb462

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

.changeset/wise-timers-look.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 muted DOM property works correctly in FF

packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ export function RegularElement(node, context) {
7777

7878
if (
7979
node.attributes.some(
80-
(attribute) => attribute.type === 'Attribute' && attribute.name === 'autofocus'
80+
(attribute) =>
81+
attribute.type === 'Attribute' &&
82+
(attribute.name === 'autofocus' || attribute.name === 'muted')
8183
)
8284
) {
8385
mark_subtree_dynamic(context.path);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export function RegularElement(node, context) {
264264
if (
265265
!is_custom_element &&
266266
attribute.name !== 'autofocus' &&
267+
attribute.name !== 'muted' &&
267268
(attribute.value === true || is_text_attribute(attribute))
268269
) {
269270
const name = get_attribute_name(node, attribute);
@@ -531,6 +532,12 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
531532
return false;
532533
}
533534

535+
// Special case for Firefox who needs it set as a property in order to work
536+
if (name === 'muted') {
537+
state.init.push(b.stmt(b.assignment('=', b.member(node_id, b.id('muted')), value)));
538+
return false;
539+
}
540+
534541
/** @type {Statement} */
535542
let update;
536543

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function is_static_element(node) {
142142
return false;
143143
}
144144

145-
if (attribute.name === 'autofocus') {
145+
if (attribute.name === 'autofocus' || attribute.name === 'muted') {
146146
return false;
147147
}
148148

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><video class="svelte-xyz" autoplay muted></video>
2-
<video muted></video></div>
1+
<div><video class="svelte-xyz" autoplay></video>
2+
<video></video></div>

0 commit comments

Comments
 (0)