Skip to content

chore: small tweaks on set_attributes() #15413

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

Closed
wants to merge 6 commits into from

Conversation

adiguba
Copy link
Contributor

@adiguba adiguba commented Mar 1, 2025

Changes :

  • The parameter skip_warning of set_attributes() was unused : now it's passed to set_attribute().
  • The value of the parameter preserve_attribute_case for <svelte:element> is now consistent with regular tags : it's true for custom elements, SVG or MathML (note : is this correct?)
  • For <svelte:element>, the value of preserve_attribute_case and is_custom_element are now evaluated when the node is created inside $.element(), and no longer at each update of the template.

Example of generated code :

-	$.element(node, tag, false, ($$element, $$anchor) => {
+	$.element(node, tag, false, ($$element, $$anchor, $$preserve_attribute_case, $$is_custom_element) => {
		let attributes;

		$.template_effect(() => attributes = $.set_attributes($$element, attributes,
				{ title: title(), ...rest }, undefined,
-				$$element.namespaceURI === $.NAMESPACE_SVG,
-				$$element.nodeName.includes('-')
+				$$preserve_attribute_case,
+				$$is_custom_element
		));
	});

Note : I don't known how to test that...

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Mar 1, 2025

🦋 Changeset detected

Latest commit: 346de0e

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

@svelte-docs-bot
Copy link

Copy link
Contributor

github-actions bot commented Mar 1, 2025

Playground

pnpm add https://pkg.pr.new/svelte@15413

? b.literal(context.state.analysis.css.hash)
: is_custom_element
? b.null
: false,
Copy link
Member

Choose a reason for hiding this comment

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

what's this change about? Why null in one case and false in the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just to generate a null instead of undefined for custom-element :

$.set_attributes(cust_elem, attributes_1, { ...rest }, undefined, true, true);
// =>
$.set_attributes(cust_elem, attributes_1, { ...rest }, null, true, true);

But maybe it's useless...

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's fine to keep it as undefined — there's probably a bunch of places where we have these arguments that are omitted in favour of defaults if there are no subsequent non-falsy arguments, and if we always added this logic it would make the codebase more cluttered. With gzip the extra characters won't matter

adiguba and others added 3 commits March 4, 2025 14:10
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
@adiguba
Copy link
Contributor Author

adiguba commented Mar 4, 2025

Just a question : what the good value for preserve_attribute_case ?

Like I said currently it's true for custom-element, SVG or MathML on RegularElement, but only on SVG for svelte:element.

I use the value on RegularElement in this PR, but I'm not sure if that's correct...

@Rich-Harris
Copy link
Member

Ah, yep. Attributes are case-sensitive on everything except regular (non-custom) HTML elements IIUC, so the check should probably be that instead.

Looking more closely at some compiled output I wonder if we should do that check inside set_attributes? Opened #15443 to compare

@Rich-Harris
Copy link
Member

merged #15443, so I'll close this PR

@Rich-Harris Rich-Harris closed this Mar 5, 2025
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.

3 participants