Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { is_mathml, is_svg, is_void } from '../../../../utils.js';
import { cannot_be_set_statically, is_mathml, is_svg, is_void } from '../../../../utils.js';
import {
is_tag_valid_with_ancestor,
is_tag_valid_with_parent
Expand Down Expand Up @@ -77,9 +77,7 @@ export function RegularElement(node, context) {

if (
node.attributes.some(
(attribute) =>
attribute.type === 'Attribute' &&
(attribute.name === 'autofocus' || attribute.name === 'muted')
(attribute) => attribute.type === 'Attribute' && cannot_be_set_statically(attribute.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic can move to Attribute visitor rather than be here.

Copy link
Member Author

@dummdidumm dummdidumm Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just strictly did replace the usage sites, not do any correctness fixes. This is meant to be a consolidation PR, nothing else

)
) {
mark_subtree_dynamic(context.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/** @import { Scope } from '../../../scope' */
import { escape_html } from '../../../../../escaping.js';
import {
cannot_be_set_statically,
is_boolean_attribute,
is_dom_property,
is_load_error_element,
Expand Down Expand Up @@ -262,8 +263,7 @@ export function RegularElement(node, context) {

if (
!is_custom_element &&
attribute.name !== 'autofocus' &&
attribute.name !== 'muted' &&
!cannot_be_set_statically(attribute.name) &&
(attribute.value === true || is_text_attribute(attribute))
) {
const name = get_attribute_name(node, attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/** @import { Scope } from '../../../../scope.js' */
/** @import { ComponentContext } from '../../types' */
import { escape_html } from '../../../../../../escaping.js';
import { cannot_be_set_statically } from '../../../../../../utils.js';
import { is_event_attribute } from '../../../../../utils/ast.js';
import * as b from '../../../../../utils/builders.js';
import { build_template_chunk, build_update } from './utils.js';
Expand Down Expand Up @@ -142,7 +143,7 @@ function is_static_element(node) {
return false;
}

if (attribute.name === 'autofocus' || attribute.name === 'muted') {
if (cannot_be_set_statically(attribute.name)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this, I think we can move this entirely?

return false;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/svelte/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ export function is_dom_property(name) {
return DOM_PROPERTIES.includes(name);
}

const NON_STATIC_PROPERTIES = ['autofocus', 'muted'];

/**
* Returns `true` if the given attribute cannot be set through the template
* string, i.e. needs some kind of JavaScript handling to work.
* @param {string} name
*/
export function cannot_be_set_statically(name) {
return NON_STATIC_PROPERTIES.includes(name);
}

/**
* Subset of delegated events which should be passive by default.
* These two are already passive via browser defaults on window, document and body.
Expand Down
Loading