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: update HTML attributes list #3018

Merged
merged 2 commits into from
Aug 25, 2022
Merged

fix: update HTML attributes list #3018

merged 2 commits into from
Aug 25, 2022

Conversation

nolanlawson
Copy link
Collaborator

@nolanlawson nolanlawson commented Aug 23, 2022

Details

Fixes #3016

Updates our list of known HTML attributes and known tag-to-attribute mapping, using this list on MDN of global attributes and the latest html-element-attributes code.

Does this pull request introduce a breaking change?

  • ✅ No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • ⚠️ Yes, it does include an observable change.

There are two observable changes:

  1. @lwc/template-compiler warnings have changed. There are some new warnings and some dropped warnings.
  2. @lwc/engine-server is also using some of these attributes to determine how to handle props:

// Handle global html attributes and AOM.
if (isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) {
return getAttribute(node, attrName);
}

Since the first involves only warnings (not errors), it should not break any existing users.

Since the second is still somewhat experimental, it also shouldn't break anyone due to the observable change.

const GLOBAL_ATTRIBUTE = new Set([
'role',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed role because it is not in MDN's list of global attributes.

This change should not be observable, because both @lwc/template-compiler and @lwc/engine-server were also checking isAriaAttribute, and it turns out that role is an ARIA attribute.

isGlobalHtmlAttribute(attrName) ||
isAriaOrDataOrFmkAttribute(attrName) ||

if (isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) {

'class',
'contenteditable',
'contextmenu',
'dir',
'draggable',
'dropzone',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

dropzone is not mentioned on MDN. In the HTML5 spec, it is described as an "obsolete" attribute:

dropzone on all elements
Use script to handle the dragenter and dragover events instead.

Removing it should not have an observable impact, except that users will get a warning whereas they didn't get a warning before.

return attrName === 'key' || attrName === 'slot';
function isFrameworkAttribute(attrName: string): boolean {
// 'key' is currently the only LWC framework-specific attribute that doesn't start with "lwc:"
return attrName === 'key';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no need to put slot here because it's already in the list of global HTML attributes, and isFrameworkAttribute is only used in one place, which is the isValidHTMLAttribute check, which already checks the list of global HTML attributes.

@@ -31,10 +31,12 @@
*/
import { hasOwnProperty } from '@lwc/shared';

// This mapping is based on https://github.com/wooorm/html-element-attributes/blob/270d8ce/index.js
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is where the original list came from, but it was not mentioned anywhere. Probably it was taken from an older version of the library, so I just updated it.

Copy link
Collaborator Author

@nolanlawson nolanlawson Aug 23, 2022

Choose a reason for hiding this comment

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

Side note: I would love to switch to just using the html-element-attributes library directly (as well as svg-element-attributes), but they dropped support for CommonJS, so we can't switch until we fix #3017.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opened #3019 to track this.

'target',
'type',
],
abbr: ['title'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some of these mappings were dropped, but again, this should only affect warnings.

@nolanlawson nolanlawson merged commit b6e266a into master Aug 25, 2022
@nolanlawson nolanlawson deleted the nolan/html-attributes branch August 25, 2022 20:05
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.

LWC template compiler warns about part attribute
2 participants