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: Use token for the styling host element instead of tag name #390

Merged
merged 7 commits into from
Jun 12, 2018

Conversation

pmdartus
Copy link
Member

@pmdartus pmdartus commented Jun 7, 2018

Details

This PR changes the way the host element gets targetted in CSS. Instead of relying on the tag name, the compiler now reuses the token to style the host element.

Fix #383

Does this PR introduce a breaking change?

  • Yes
  • No

@pmdartus pmdartus requested review from caridy and davidturissini June 7, 2018 16:54
Copy link
Contributor

@davidturissini davidturissini left a comment

Choose a reason for hiding this comment

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

Minor test update

const cmp = createElement('x-cmp', { is: Component });
document.body.appendChild(cmp);

expect(querySelectorAll.call(cmp, 'div[token]').length).toBe(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

use cmp.shadowRoot.querySelectorAll

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: d1cf4a7 | Target commit: 08ee60e

lwc-engine-benchmark

table-append-1k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table/append/1k duration 142.90 (± 4.00 ms) 142.60 (± 4.35 ms) 0.21% 👌
table-clear-1k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table/clear/1k duration 11.00 (± 0.50 ms) 11.30 (± 0.40 ms) -2.73% 👌
table-create-10k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table/create/10k duration 834.20 (± 6.50 ms) 832.80 (± 8.70 ms) 0.17% 👌
table-create-1k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table/create/1k duration 100.10 (± 1.85 ms) 100.90 (± 2.10 ms) -0.80% 👌
table-update-10th-1k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table/update-10th/1k duration 91.60 (± 4.40 ms) 91.00 (± 3.70 ms) 0.66% 👌
tablecmp-append-1k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table-component/append/1k duration 259.80 (± 5.10 ms) 256.40 (± 4.20 ms) 1.31% 👍
tablecmp-clear-1k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table/clear/1k duration 34.65 (± 1.15 ms) 34.60 (± 1.80 ms) 0.14% 👌
tablecmp-create-10k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table-component/create/10k duration 1681.70 (± 9.80 ms) 1684.40 (± 12.90 ms) -0.16% 👌
tablecmp-create-1k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table-component/create/1k duration 196.00 (± 4.30 ms) 195.80 (± 4.20 ms) 0.10% 👌
tablecmp-update-10th-1k metric base(d1cf4a7) target(08ee60e) trend
benchmark-table-component/update-10th/1k duration 75.40 (± 3.40 ms) 73.90 (± 3.90 ms) 1.99% 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 800002c | Target commit: 5541acc

lwc-engine-benchmark

table-append-1k metric base(800002c) target(5541acc) trend
benchmark-table/append/1k duration 143.90 (± 3.30 ms) 146.70 (± 5.30 ms) -1.95% 👌
table-clear-1k metric base(800002c) target(5541acc) trend
benchmark-table/clear/1k duration 11.60 (± 0.40 ms) 11.35 (± 0.45 ms) 2.16% 👌
table-create-10k metric base(800002c) target(5541acc) trend
benchmark-table/create/10k duration 833.40 (± 4.30 ms) 857.20 (± 4.60 ms) -2.86% 👎
table-create-1k metric base(800002c) target(5541acc) trend
benchmark-table/create/1k duration 98.40 (± 1.80 ms) 99.80 (± 1.60 ms) -1.42% 👌
table-update-10th-1k metric base(800002c) target(5541acc) trend
benchmark-table/update-10th/1k duration 85.50 (± 4.45 ms) 87.30 (± 5.40 ms) -2.11% 👌
tablecmp-append-1k metric base(800002c) target(5541acc) trend
benchmark-table-component/append/1k duration 251.20 (± 4.10 ms) 259.90 (± 4.30 ms) -3.46% 👎
tablecmp-clear-1k metric base(800002c) target(5541acc) trend
benchmark-table/clear/1k duration 36.90 (± 1.50 ms) 36.40 (± 2.00 ms) 1.36% 👌
tablecmp-create-10k metric base(800002c) target(5541acc) trend
benchmark-table-component/create/10k duration 1705.80 (± 18.40 ms) 1688.30 (± 7.00 ms) 1.03% 👍
tablecmp-create-1k metric base(800002c) target(5541acc) trend
benchmark-table-component/create/1k duration 198.15 (± 4.80 ms) 198.70 (± 4.10 ms) -0.28% 👌
tablecmp-update-10th-1k metric base(800002c) target(5541acc) trend
benchmark-table-component/update-10th/1k duration 74.70 (± 4.10 ms) 74.80 (± 4.10 ms) -0.13% 👌

@@ -65,12 +73,14 @@ function applyTokenToHost(vm: VM, html: Template): void {
// Remove the token currently applied to the host element if different than the one associated
// with the current template
if (!isUndefined(oldToken)) {
removeAttribute.call(host, oldToken);
const oldHostToken = hostToken(oldToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

why isn't the token that we use in the engine already using the -host postfix? why does the engine needs to know this?

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.

I don't think the engine should know how to build such token, it should come from compiler, and the engine should just pass it around.

@pmdartus
Copy link
Member Author

@caridy Ready for review, the engine now expect 2 properties on the template, hostToken and shadowToken.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 598d940 | Target commit: 6d7ea46

lwc-engine-benchmark

table-append-1k metric base(598d940) target(6d7ea46) trend
benchmark-table/append/1k duration 144.80 (± 4.40 ms) 149.50 (± 6.70 ms) -3.25% 👎
table-clear-1k metric base(598d940) target(6d7ea46) trend
benchmark-table/clear/1k duration 11.40 (± 0.30 ms) 11.80 (± 0.40 ms) -3.51% 👎
table-create-10k metric base(598d940) target(6d7ea46) trend
benchmark-table/create/10k duration 838.90 (± 3.40 ms) 852.10 (± 4.90 ms) -1.57% 👎
table-create-1k metric base(598d940) target(6d7ea46) trend
benchmark-table/create/1k duration 100.90 (± 1.80 ms) 101.50 (± 1.60 ms) -0.59% 👌
table-update-10th-1k metric base(598d940) target(6d7ea46) trend
benchmark-table/update-10th/1k duration 91.10 (± 5.80 ms) 91.60 (± 5.90 ms) -0.55% 👌
tablecmp-append-1k metric base(598d940) target(6d7ea46) trend
benchmark-table-component/append/1k duration 253.50 (± 4.40 ms) 262.80 (± 4.90 ms) -3.67% 👎
tablecmp-clear-1k metric base(598d940) target(6d7ea46) trend
benchmark-table/clear/1k duration 36.40 (± 1.70 ms) 36.30 (± 2.40 ms) 0.27% 👌
tablecmp-create-10k metric base(598d940) target(6d7ea46) trend
benchmark-table-component/create/10k duration 1714.10 (± 16.60 ms) 1688.30 (± 12.30 ms) 1.51% 👍
tablecmp-create-1k metric base(598d940) target(6d7ea46) trend
benchmark-table-component/create/1k duration 199.90 (± 5.00 ms) 201.30 (± 5.30 ms) -0.70% 👌
tablecmp-update-10th-1k metric base(598d940) target(6d7ea46) trend
benchmark-table-component/update-10th/1k duration 74.90 (± 4.40 ms) 76.90 (± 4.30 ms) -2.67% 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 231e00d | Target commit: 77f52e1

lwc-engine-benchmark

table-append-1k metric base(231e00d) target(77f52e1) trend
benchmark-table/append/1k duration 147.40 (± 4.60 ms) 149.20 (± 6.30 ms) -1.22% 👌
table-clear-1k metric base(231e00d) target(77f52e1) trend
benchmark-table/clear/1k duration 11.80 (± 0.30 ms) 11.30 (± 0.50 ms) 4.24% 👍
table-create-10k metric base(231e00d) target(77f52e1) trend
benchmark-table/create/10k duration 847.50 (± 4.50 ms) 846.10 (± 3.40 ms) 0.17% 👌
table-create-1k metric base(231e00d) target(77f52e1) trend
benchmark-table/create/1k duration 101.60 (± 2.00 ms) 101.10 (± 1.50 ms) 0.49% 👌
table-update-10th-1k metric base(231e00d) target(77f52e1) trend
benchmark-table/update-10th/1k duration 89.60 (± 5.90 ms) 86.40 (± 6.20 ms) 3.57% 👌
tablecmp-append-1k metric base(231e00d) target(77f52e1) trend
benchmark-table-component/append/1k duration 255.00 (± 4.40 ms) 259.40 (± 5.50 ms) -1.73% 👌
tablecmp-clear-1k metric base(231e00d) target(77f52e1) trend
benchmark-table/clear/1k duration 35.60 (± 1.40 ms) 35.70 (± 1.50 ms) -0.28% 👌
tablecmp-create-10k metric base(231e00d) target(77f52e1) trend
benchmark-table-component/create/10k duration 1722.50 (± 18.10 ms) 1748.00 (± 7.70 ms) -1.48% 👎
tablecmp-create-1k metric base(231e00d) target(77f52e1) trend
benchmark-table-component/create/1k duration 200.00 (± 3.40 ms) 198.30 (± 4.00 ms) 0.85% 👌
tablecmp-update-10th-1k metric base(231e00d) target(77f52e1) trend
benchmark-table-component/update-10th/1k duration 76.10 (± 4.60 ms) 75.30 (± 2.60 ms) 1.05% 👌

@pmdartus pmdartus merged commit cccc63d into master Jun 12, 2018
@pmdartus pmdartus deleted the pmdartus/style-compilation-simplication branch June 12, 2018 18:11
pmdartus added a commit that referenced this pull request Jun 13, 2018
## Details

Fix unit test failing due to conflicting merges between #390 and #397

## Does this PR introduce a breaking change?

* [ ] Yes
* [X] No
pmdartus added a commit that referenced this pull request Jun 13, 2018
## Details

Cleanup old style related code in the compiler:
* remove `style` property from the component class. The style injection is now done at evaluation time and doesn't rely on an external system to inject it. (obsolete since #302)
* Remove `tagName` parameter from `stylesheet` factory. (obsolete since #390)

## Does this PR introduce a breaking change?

* [ ] Yes
* [X] No
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