Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve element class attribute behaviour #10856

Merged
merged 2 commits into from
Mar 21, 2024
Merged

fix: improve element class attribute behaviour #10856

merged 2 commits into from
Mar 21, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Mar 21, 2024

This PR does two things:

  • Fixes a bug with SVG elements where we were incorrectly treating dom.className as a string, when it's really an object in the form of SVGAnimatedString. Instead we use a dedicated SVG class name path that is better optimized for this case.
  • When dealing with class if the value is nullish then we remove the attribute, otherwise we keep it and make it empty. This seems to have a big performance impact, where removing the attribute is causing additional reflows vs just changing it to an empty string.

Copy link

changeset-bot bot commented Mar 21, 2024

🦋 Changeset detected

Latest commit: 4079edd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

packages/svelte/src/internal/client/dom/elements/class.js Outdated Show resolved Hide resolved
* @param {string} value
* @returns {void}
*/
export function svg_class_name(dom, value) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to code-golf this: add a boolean which is true by default, and when true it uses the regular dom element variant, else the "always attribute" variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow? We can't use the class_name variant at all here as it does set_class_name.

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants