-
Notifications
You must be signed in to change notification settings - Fork 402
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(css-compiler): relaxation of attribute css rules #1248
Conversation
word: attributeName, | ||
}); | ||
} | ||
function validateAttribute(root: Root, result: null | Result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has the important logic, is difficult to see here in the diff because i replaced the root.walk() + if (isAttribute(node))
with the walkAttributes
helper function.
Benchmark resultsBase commit: lwc-engine-benchmark
|
[ | ||
{ | ||
"type": "warning", | ||
"text": "Invalid usage of attribute selector \"custom-attribute\". Attribute \"custom-attribute\" is not a known attribute on <x-foo> element.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this warning should probably change to something less strong... it is saying invalid
at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the warning more polite.
Benchmark resultsBase commit: lwc-engine-benchmark
|
@@ -1,7 +1,7 @@ | |||
[ | |||
{ | |||
"type": "warning", | |||
"text": "Invalid usage of attribute selector \"custom-attribute\". Attribute \"custom-attribute\" is not a known attribute on <x-foo> element.", | |||
"text": "Attribute \"custom-attribute\" is not a known attribute on <x-foo> element.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is an unknown
maybe @ekashida or @jbleyleSF can help with the wording of the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an issue with the proposed changes because it feels like we're taking a step backwards in terms of user experience. We've already seen that warnings are difficult to manage and users learn to ignore warnings as soon as we introduce noise. I would rather see a solution where we either 1) abandon this type of validation, 2) keep the errors but introduce a way for the user to have the compiler ignore it via ignore comments, or 3) as @pmdartus has mentioned elsewhere, move this validation to a CSS linter.
It seems that neither (1) nor (2) are blockers for the ideal solution (3). Maybe we can just remove everything for now?
'lwc:dom', | ||
'if:true', | ||
'if:false', | ||
'for:each', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing:
for:item
for:index
iterator:*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think have a wildcard helps... something like lwc:*
and for:
and iterator:*
|
||
const DEPRECATED_SELECTORS = new Set(['/deep/', '::shadow', '>>>']); | ||
const UNSUPPORTED_SELECTORS = new Set(['::slotted', ':root', ':host-context']); | ||
const LWC_RESERVED_ATTRIBUTE_SELECTORS = new Set([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be referring to these as "template directives" here and in the corresponding error messages since that they are not normal attributes.
Removes the validation rule: unknown attribute without a tag. Reason: Before: if you have a rule .foo[disabled]: {}, the css compiler would throw with message Invalid usage of attribute selector disabled. For validation purposes, attributes that are not global attributes must be associated with a tag name when used in a CSS selector. This rule can be valid for simplicity purposes, the disabled attribute is valid in button, fieldset, input etc. thus having this one rule makes sense, with the restriction you would need 3 (or more) rules
removes css attribute restriction: unknownattribute on known element
b42e100
to
4029500
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
if (isTemplateDirective) { | ||
const message = [ | ||
`Invalid usage of attribute selector "${attributeName}". `, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid attribute selector "${attributeName}".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As i see it, is not that the attribute selector is invalid, is that we don't allow it to be used in LWC.
if (isTemplateDirective) { | ||
const message = [ | ||
`Invalid usage of attribute selector "${attributeName}". `, | ||
`"${attributeName}" is a template directive and therefore not supported in css rules.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Template directives cannot be used as selectors because they are not real attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont completely agree with not real attributes
, but if this makes more sense to customers than the proposed, im fine changing the message. thoughts @jbleyleSF ?
Details
Addresses issue #1219
Without this PR, the css compilation currently fails with:
1- Unknown attributes in known selectors:
2- Unknown attributes without a tag:
3- Attributes in custom elements (is a consequence of (1))
With this PR, we:
[key='entity-id'] {}
or[iterator:iteratorName] {}
Does this PR introduce a breaking change?