Skip to content

fix: Regression itemscope as boolean_attribute #8414

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

Merged
merged 3 commits into from
Mar 27, 2023

Conversation

aMediocreDad
Copy link
Contributor

@aMediocreDad aMediocreDad commented Mar 24, 2023

Note Referenced Issue: #8413

Microdata

Microdata are a strange set of attributes which are ONLY defined in markup, and have no relationship to the underlying Document Object Model node. As such programmatically defining an element and setting a property on it with a given Microdata attribute will not work:
https://codepen.io/iambrosius/full/jOvXBBG

One can read more about microdata here: https://developer.mozilla.org/en-US/docs/Web/HTML/Microdata

The Problem

When an attribute is declared in the set of boolean_attributes:

const _boolean_attributes = [

And here:

const attribute_lookup: { [key in BooleanAttributes]: AttributeMetadata } & { [key in string]: AttributeMetadata } = {

The generated code looks like this:

function create_fragment(ctx) {
	let div$;

	return {
		c() {
			div$ = element$("div");
			div$.itemscope = true; // <- This line!
		},
		m(target, anchor) {
			insert$(target, div$, anchor);
		},
		p: noop$,
		i: noop$,
		o: noop$,
		d(detaching) {
			if (detaching) detach$(div$);
		}
	};
}

The output above will not work as expected because, again, Microdata has no relationship to the underlying document node (it is strictly defined in markup).

This PR rewrites the itemscope test to be more accurate of what itemscope is intended to be, along with removing the declaration of itemscope as a boolean attribute in the respective files above.

In addition it adds a test for the hidden attribute which is an attribute actually tied to the equivalent dom node property.

I hope this helps prevent future regressions from happening


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.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@vercel
Copy link

vercel bot commented Mar 24, 2023

@aMediocreDad is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@aMediocreDad aMediocreDad changed the title Global Attributes fix fix: Global Attributes relying on browser implementation Mar 24, 2023
@aMediocreDad aMediocreDad marked this pull request as ready for review March 24, 2023 10:16
@aMediocreDad aMediocreDad changed the title fix: Global Attributes relying on browser implementation fix: Remove itemscope from boolean_attributes dict Mar 24, 2023
@aMediocreDad aMediocreDad force-pushed the global-attributes-fix branch from dddbe7b to 623cff0 Compare March 24, 2023 10:30
@aMediocreDad aMediocreDad force-pushed the global-attributes-fix branch from 623cff0 to a8c80d0 Compare March 24, 2023 10:35
@aMediocreDad
Copy link
Contributor Author

In the future, Microdata attributes should be handled in a similar fashion to xlink attributes. I would love to help with this, but uncertain of where to start.

@aMediocreDad aMediocreDad changed the title fix: Remove itemscope from boolean_attributes dict fix: Regression itemscope as boolean_attribute Mar 24, 2023
@aMediocreDad
Copy link
Contributor Author

Converted the itemscope test to a more general microdata test that should prevent regression in the setting of microdata attributes.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Thank you!

@dummdidumm dummdidumm merged commit 1333be0 into sveltejs:master Mar 27, 2023
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.

2 participants