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(css-compiler): relaxation of attribute css rules #1248

Merged
merged 3 commits into from
May 24, 2019

Conversation

jodarove
Copy link
Contributor

@jodarove jodarove commented May 20, 2019

Details

Addresses issue #1219

Without this PR, the css compilation currently fails with:

1- Unknown attributes in known selectors:

div[min] {}

2- Unknown attributes without a tag:

.foo[disabled] {}

3- Attributes in custom elements (is a consequence of (1))

x-foo[custom-attribute]

With this PR, we:

  • Removed css restrictions 1, 2 and 3.
  • Adds a new restriction to use template directive in css rules. Ex: [key='entity-id'] {} or [iterator:iteratorName] {}

Does this PR introduce a breaking change?

  • Yes
  • No

word: attributeName,
});
}
function validateAttribute(root: Root, result: null | Result) {
Copy link
Contributor Author

@jodarove jodarove May 20, 2019

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.

@jodarove jodarove requested review from pmdartus, diervo and caridy May 20, 2019 22:41
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 1dc9f30 | Target commit: 6bb32f7

lwc-engine-benchmark

table-append-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table/append/1k duration 146.90 (±3.10 ms) 150.45 (±4.35 ms) +3.5ms (2.4%) 👎
table-clear-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table/clear/1k duration 11.20 (±0.85 ms) 11.50 (±0.55 ms) +0.3ms (2.7%) 👌
table-create-10k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table/create/10k duration 885.00 (±6.35 ms) 883.15 (±5.55 ms) -1.9ms (0.2%) 👌
table-create-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table/create/1k duration 121.05 (±3.05 ms) 119.50 (±3.00 ms) -1.5ms (1.3%) 👌
table-update-10th-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table/update-10th/1k duration 67.80 (±1.40 ms) 67.75 (±1.90 ms) -0.1ms (0.1%) 👌
tablecmp-append-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-component/append/1k duration 225.20 (±9.60 ms) 225.05 (±10.10 ms) -0.1ms (0.1%) 👌
tablecmp-clear-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-component/clear/1k duration 7.05 (±1.55 ms) 6.75 (±1.20 ms) -0.3ms (4.3%) 👌
tablecmp-create-10k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-component/create/10k duration 1711.95 (±14.35 ms) 1711.10 (±15.30 ms) -0.9ms (0.0%) 👌
tablecmp-create-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-component/create/1k duration 209.55 (±4.35 ms) 208.35 (±4.45 ms) -1.2ms (0.6%) 👌
tablecmp-update-10th-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-component/update-10th/1k duration 65.95 (±4.65 ms) 66.00 (±4.00 ms) +0.1ms (0.1%) 👌
wc-append-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-wc/append/1k duration 225.15 (±16.20 ms) 230.80 (±15.90 ms) +5.7ms (2.5%) 👌
wc-clear-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-wc/clear/1k duration 12.00 (±1.40 ms) 11.40 (±1.60 ms) -0.6ms (5.0%) 👌
wc-create-10k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-wc/create/10k duration 1829.30 (±19.85 ms) 1857.45 (±21.90 ms) +28.1ms (1.5%) 👎
wc-create-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-wc/create/1k duration 212.45 (±5.70 ms) 214.50 (±6.45 ms) +2.1ms (1.0%) 👌
wc-update-10th-1k metric base(1dc9f30) target(6bb32f7) trend
benchmark-table-wc/update-10th/1k duration 66.45 (±4.60 ms) 68.25 (±4.90 ms) +1.8ms (2.7%) 👌

[
{
"type": "warning",
"text": "Invalid usage of attribute selector \"custom-attribute\". Attribute \"custom-attribute\" is not a known attribute on <x-foo> element.",
Copy link
Contributor

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.

Copy link
Contributor

@caridy caridy left a 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.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 1dc9f30 | Target commit: b42e100

lwc-engine-benchmark

table-append-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table/append/1k duration 146.90 (±3.10 ms) 152.05 (±4.00 ms) +5.2ms (3.5%) 👎
table-clear-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table/clear/1k duration 11.20 (±0.85 ms) 11.50 (±0.85 ms) +0.3ms (2.7%) 👌
table-create-10k metric base(1dc9f30) target(b42e100) trend
benchmark-table/create/10k duration 885.00 (±6.35 ms) 882.10 (±8.35 ms) -2.9ms (0.3%) 👍
table-create-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table/create/1k duration 121.05 (±3.05 ms) 117.05 (±3.15 ms) -4.0ms (3.3%) 👍
table-update-10th-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table/update-10th/1k duration 67.80 (±1.40 ms) 69.05 (±2.00 ms) +1.2ms (1.8%) 👌
tablecmp-append-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table-component/append/1k duration 225.20 (±9.60 ms) 227.55 (±7.70 ms) +2.4ms (1.0%) 👌
tablecmp-clear-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table-component/clear/1k duration 7.05 (±1.55 ms) 6.65 (±1.45 ms) -0.4ms (5.7%) 👌
tablecmp-create-10k metric base(1dc9f30) target(b42e100) trend
benchmark-table-component/create/10k duration 1711.95 (±14.35 ms) 1712.70 (±12.95 ms) +0.7ms (0.0%) 👌
tablecmp-create-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table-component/create/1k duration 209.55 (±4.35 ms) 210.30 (±6.05 ms) +0.8ms (0.4%) 👌
tablecmp-update-10th-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table-component/update-10th/1k duration 65.95 (±4.65 ms) 64.55 (±3.70 ms) -1.4ms (2.1%) 👌
wc-append-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table-wc/append/1k duration 225.15 (±16.20 ms) 227.05 (±15.15 ms) +1.9ms (0.8%) 👌
wc-clear-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table-wc/clear/1k duration 12.00 (±1.40 ms) 11.65 (±1.55 ms) -0.4ms (2.9%) 👌
wc-create-10k metric base(1dc9f30) target(b42e100) trend
benchmark-table-wc/create/10k duration 1829.30 (±19.85 ms) 1819.40 (±14.20 ms) -9.9ms (0.5%) 👌
wc-create-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table-wc/create/1k duration 212.45 (±5.70 ms) 212.75 (±5.50 ms) +0.3ms (0.1%) 👌
wc-update-10th-1k metric base(1dc9f30) target(b42e100) trend
benchmark-table-wc/update-10th/1k duration 66.45 (±4.60 ms) 68.00 (±5.45 ms) +1.5ms (2.3%) 👌

@jodarove jodarove requested a review from caridy May 21, 2019 00:12
@@ -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.",
Copy link
Contributor

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

Copy link
Member

@ekashida ekashida left a 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',
Copy link
Member

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:*

Copy link
Contributor

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([
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 we should be referring to these as "template directives" here and in the corresponding error messages since that they are not normal attributes.

jodarove added 3 commits May 23, 2019 21:59
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
@jodarove jodarove force-pushed the jodarove/css-remove-attribute-validation branch from b42e100 to 4029500 Compare May 24, 2019 06:05
@jodarove jodarove requested a review from ekashida May 24, 2019 06:07
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 38960e5 | Target commit: 4029500

lwc-engine-benchmark

table-append-1k metric base(38960e5) target(4029500) trend
benchmark-table/append/1k duration 143.55 (±4.15 ms) 139.70 (±4.60 ms) -3.9ms (2.7%) 👍
table-clear-1k metric base(38960e5) target(4029500) trend
benchmark-table/clear/1k duration 10.20 (±0.90 ms) 10.40 (±1.00 ms) +0.2ms (2.0%) 👌
table-create-10k metric base(38960e5) target(4029500) trend
benchmark-table/create/10k duration 849.95 (±6.20 ms) 841.90 (±5.45 ms) -8.0ms (0.9%) 👍
table-create-1k metric base(38960e5) target(4029500) trend
benchmark-table/create/1k duration 107.60 (±2.25 ms) 108.20 (±3.50 ms) +0.6ms (0.6%) 👌
table-update-10th-1k metric base(38960e5) target(4029500) trend
benchmark-table/update-10th/1k duration 68.80 (±2.30 ms) 68.30 (±2.50 ms) -0.5ms (0.7%) 👌
tablecmp-append-1k metric base(38960e5) target(4029500) trend
benchmark-table-component/append/1k duration 220.50 (±14.50 ms) 212.50 (±16.45 ms) -8.0ms (3.6%) 👍
tablecmp-clear-1k metric base(38960e5) target(4029500) trend
benchmark-table-component/clear/1k duration 7.35 (±1.35 ms) 6.95 (±1.25 ms) -0.4ms (5.4%) 👌
tablecmp-create-10k metric base(38960e5) target(4029500) trend
benchmark-table-component/create/10k duration 1612.10 (±9.70 ms) 1615.05 (±12.85 ms) +3.0ms (0.2%) 👌
tablecmp-create-1k metric base(38960e5) target(4029500) trend
benchmark-table-component/create/1k duration 184.85 (±4.90 ms) 182.20 (±4.85 ms) -2.7ms (1.4%) 👌
tablecmp-update-10th-1k metric base(38960e5) target(4029500) trend
benchmark-table-component/update-10th/1k duration 65.85 (±4.80 ms) 67.35 (±4.05 ms) +1.5ms (2.3%) 👌
wc-append-1k metric base(38960e5) target(4029500) trend
benchmark-table-wc/append/1k duration 244.15 (±12.00 ms) 238.95 (±13.35 ms) -5.2ms (2.1%) 👌
wc-clear-1k metric base(38960e5) target(4029500) trend
benchmark-table-wc/clear/1k duration 12.35 (±1.50 ms) 11.65 (±1.45 ms) -0.7ms (5.7%) 👌
wc-create-10k metric base(38960e5) target(4029500) trend
benchmark-table-wc/create/10k duration 1794.70 (±6.70 ms) 1735.80 (±8.40 ms) -58.9ms (3.3%) 👍
wc-create-1k metric base(38960e5) target(4029500) trend
benchmark-table-wc/create/1k duration 201.10 (±3.90 ms) 201.80 (±5.40 ms) +0.7ms (0.3%) 👌
wc-update-10th-1k metric base(38960e5) target(4029500) trend
benchmark-table-wc/update-10th/1k duration 67.40 (±4.35 ms) 64.60 (±4.55 ms) -2.8ms (4.2%) 👍

Copy link
Member

@ekashida ekashida left a 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}". `,
Copy link
Member

Choose a reason for hiding this comment

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

Invalid attribute selector "${attributeName}".

Copy link
Contributor Author

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.`,
Copy link
Member

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.

Copy link
Contributor Author

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 ?

@jodarove jodarove merged commit 35fb5f5 into master May 24, 2019
@jodarove jodarove deleted the jodarove/css-remove-attribute-validation branch May 24, 2019 17:38
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.

4 participants