Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@augustjk
Copy link
Member

Fixes #2574

No longer subsume expressions into text if they follow a = with the assumption being they are placed as a value of a html attribute, allowing lit-html to parse them properly.

This PR also corrects an oversight from #2405 where we were returning the old template rather than newTemplate if we had a simple string literal after applying translation.

@augustjk augustjk requested a review from aomarks March 31, 2022 22:51
@augustjk augustjk requested a review from justinfagnani as a code owner March 31, 2022 22:51
@changeset-bot
Copy link

changeset-bot bot commented Mar 31, 2022

🦋 Changeset detected

Latest commit: a905a15

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 31, 2022

📊 Tachometer Benchmark Results

Summary

nop-update

  • lit-html-kitchen-sink: unsure 🔍 -6% - +1% (-1.55ms - +0.25ms)
    this-change vs tip-of-tree

render

  • lit-element-list: unsure 🔍 -3% - +1% (-2.05ms - +0.62ms)
    this-change vs tip-of-tree
  • lit-html-kitchen-sink: unsure 🔍 -4% - +3% (-1.17ms - +0.73ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -3% - +3% (-0.25ms - +0.32ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -2% - +2% (-0.94ms - +0.91ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -2% - +2% (-1.14ms - +1.10ms)
    this-change vs tip-of-tree

update

  • lit-element-list: unsure 🔍 -2% - +1% (-12.72ms - +8.54ms)
    this-change vs tip-of-tree
  • lit-html-kitchen-sink: unsure 🔍 -4% - +3% (-3.11ms - +2.49ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -1% - +3% (-3.68ms - +9.09ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -3% - +2% (-3.21ms - +2.23ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -2% - +2% (-13.20ms - +11.77ms)
    this-change vs tip-of-tree

update-reflect

  • lit-element-list: unsure 🔍 -2% - +1% (-14.54ms - +5.51ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -1% - +2% (-7.59ms - +14.04ms)
    this-change vs tip-of-tree

Results

lit-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
64.30ms - 65.91ms-unsure 🔍
-3% - +1%
-2.05ms - +0.62ms
faster ✔
19% - 22%
15.10ms - 17.87ms
tip-of-tree
tip-of-tree
64.76ms - 66.89msunsure 🔍
-1% - +3%
-0.62ms - +2.05ms
-faster ✔
18% - 21%
14.22ms - 17.32ms
previous-release
previous-release
80.46ms - 82.72msslower ❌
23% - 28%
15.10ms - 17.87ms
slower ❌
21% - 27%
14.22ms - 17.32ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
623.23ms - 635.76ms-unsure 🔍
-2% - +1%
-12.72ms - +8.54ms
faster ✔
8% - 11%
58.08ms - 76.57ms
tip-of-tree
tip-of-tree
623.00ms - 640.17msunsure 🔍
-1% - +2%
-8.54ms - +12.72ms
-faster ✔
8% - 11%
54.29ms - 76.19ms
previous-release
previous-release
690.03ms - 703.62msslower ❌
9% - 12%
58.08ms - 76.57ms
slower ❌
8% - 12%
54.29ms - 76.19ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
714.06ms - 726.22ms-unsure 🔍
-2% - +1%
-14.54ms - +5.51ms
faster ✔
4% - 6%
29.17ms - 47.50ms
tip-of-tree
tip-of-tree
716.68ms - 732.62msunsure 🔍
-1% - +2%
-5.51ms - +14.54ms
-faster ✔
3% - 6%
23.30ms - 44.34ms
previous-release
previous-release
751.61ms - 765.34msslower ❌
4% - 7%
29.17ms - 47.50ms
slower ❌
3% - 6%
23.30ms - 44.34ms
-
lit-html-kitchen-sink

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
27.25ms - 28.63ms-unsure 🔍
-4% - +3%
-1.17ms - +0.73ms
faster ✔
14% - 21%
4.55ms - 7.10ms
tip-of-tree
tip-of-tree
27.51ms - 28.81msunsure 🔍
-3% - +4%
-0.73ms - +1.17ms
-faster ✔
13% - 20%
4.36ms - 6.86ms
previous-release
previous-release
32.70ms - 34.83msslower ❌
16% - 26%
4.55ms - 7.10ms
slower ❌
15% - 25%
4.36ms - 6.86ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
74.88ms - 78.96ms-unsure 🔍
-4% - +3%
-3.11ms - +2.49ms
unsure 🔍
-4% - +4%
-3.14ms - +2.71ms
tip-of-tree
tip-of-tree
75.31ms - 79.15msunsure 🔍
-3% - +4%
-2.49ms - +3.11ms
-unsure 🔍
-4% - +4%
-2.74ms - +2.94ms
previous-release
previous-release
75.04ms - 79.23msunsure 🔍
-4% - +4%
-2.71ms - +3.14ms
unsure 🔍
-4% - +4%
-2.94ms - +2.74ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
23.19ms - 24.46ms-unsure 🔍
-6% - +1%
-1.55ms - +0.25ms
faster ✔
11% - 17%
2.88ms - 4.83ms
tip-of-tree
tip-of-tree
23.83ms - 25.12msunsure 🔍
-1% - +7%
-0.25ms - +1.55ms
-faster ✔
8% - 15%
2.22ms - 4.19ms
previous-release
previous-release
26.93ms - 28.43msslower ❌
12% - 21%
2.88ms - 4.83ms
slower ❌
9% - 17%
2.22ms - 4.19ms
-
lit-html-repeat

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
9.45ms - 9.88ms-unsure 🔍
-3% - +3%
-0.25ms - +0.32ms
faster ✔
10% - 17%
1.11ms - 1.90ms
tip-of-tree
tip-of-tree
9.44ms - 9.82msunsure 🔍
-3% - +3%
-0.32ms - +0.25ms
-faster ✔
11% - 17%
1.15ms - 1.93ms
previous-release
previous-release
10.83ms - 11.51msslower ❌
11% - 20%
1.11ms - 1.90ms
slower ❌
12% - 20%
1.15ms - 1.93ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
263.12ms - 273.17ms-unsure 🔍
-1% - +3%
-3.68ms - +9.09ms
faster ✔
28% - 31%
107.90ms - 121.04ms
tip-of-tree
tip-of-tree
261.50ms - 269.38msunsure 🔍
-3% - +1%
-9.09ms - +3.68ms
-faster ✔
29% - 32%
111.38ms - 122.97ms
previous-release
previous-release
378.38ms - 386.86msslower ❌
40% - 46%
107.90ms - 121.04ms
slower ❌
41% - 47%
111.38ms - 122.97ms
-
lit-html-template-heavy

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
47.39ms - 48.71ms-unsure 🔍
-2% - +2%
-0.94ms - +0.91ms
faster ✔
15% - 20%
8.57ms - 11.75ms
tip-of-tree
tip-of-tree
47.42ms - 48.71msunsure 🔍
-2% - +2%
-0.91ms - +0.94ms
-faster ✔
15% - 20%
8.56ms - 11.73ms
previous-release
previous-release
56.76ms - 59.66msslower ❌
18% - 25%
8.57ms - 11.75ms
slower ❌
18% - 25%
8.56ms - 11.73ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
99.31ms - 103.51ms-unsure 🔍
-3% - +2%
-3.21ms - +2.23ms
faster ✔
13% - 18%
15.86ms - 22.16ms
tip-of-tree
tip-of-tree
100.17ms - 103.63msunsure 🔍
-2% - +3%
-2.23ms - +3.21ms
-faster ✔
13% - 18%
15.60ms - 21.44ms
previous-release
previous-release
118.07ms - 122.77msslower ❌
15% - 22%
15.86ms - 22.16ms
slower ❌
15% - 21%
15.60ms - 21.44ms
-
reactive-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
47.13ms - 48.56ms-unsure 🔍
-2% - +2%
-1.14ms - +1.10ms
unsure 🔍
-1% - +3%
-0.49ms - +1.34ms
tip-of-tree
tip-of-tree
47.01ms - 48.72msunsure 🔍
-2% - +2%
-1.10ms - +1.14ms
-unsure 🔍
-1% - +3%
-0.58ms - +1.47ms
previous-release
previous-release
46.86ms - 47.99msunsure 🔍
-3% - +1%
-1.34ms - +0.49ms
unsure 🔍
-3% - +1%
-1.47ms - +0.58ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
648.48ms - 665.93ms-unsure 🔍
-2% - +2%
-13.20ms - +11.77ms
unsure 🔍
-1% - +3%
-4.85ms - +18.01ms
tip-of-tree
tip-of-tree
648.99ms - 666.85msunsure 🔍
-2% - +2%
-11.77ms - +13.20ms
-unsure 🔍
-1% - +3%
-4.29ms - +18.89ms
previous-release
previous-release
643.23ms - 658.01msunsure 🔍
-3% - +1%
-18.01ms - +4.85ms
unsure 🔍
-3% - +1%
-18.89ms - +4.29ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
749.12ms - 765.28ms-unsure 🔍
-1% - +2%
-7.59ms - +14.04ms
unsure 🔍
-1% - +2%
-8.11ms - +16.06ms
tip-of-tree
tip-of-tree
746.79ms - 761.17msunsure 🔍
-2% - +1%
-14.04ms - +7.59ms
-unsure 🔍
-1% - +2%
-10.76ms - +12.26ms
previous-release
previous-release
744.24ms - 762.22msunsure 🔍
-2% - +1%
-16.06ms - +8.11ms
unsure 🔍
-2% - +1%
-12.26ms - +10.76ms
-

tachometer-reporter-action v2 for Benchmarks

Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

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

Awesome! Just a small request for an extra test, and a question.

);
});

test('html(msg(string)) with msg as attr value', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add one with a .bar property attribute, too? Same result, just for completeness.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, and also added additional tests for having multiple attributes in a single template expression so as to test the logic for looking at both the head and the middle.

Copy link
Member

Choose a reason for hiding this comment

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

Nice!

);
}
return template;
return newTemplate;
Copy link
Member

Choose a reason for hiding this comment

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

Oops! Do the tests in this PR fail if this is switched back to template? If not, is there a test we could add that would cover it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Upon taking a closer look now, it seems we never enter this code block if a translation does occur because then newTemplate would always be a ts.TemplateLiteral. The only time we enter this block is when we don't have to translate, i.e. generating original locale's version of the source, in which case newTemplate would not have changed from it's original assignment from template here:

let newTemplate = template;

So.. it was technically an oversight but of no consequence, hence none of our existing tests failed. For readability's sake I think keeping newTemplate here still makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

sgtm

@augustjk augustjk requested a review from aomarks April 1, 2022 00:05
Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

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

Looks great

@augustjk augustjk merged commit c41a92c into main Apr 1, 2022
@augustjk augustjk deleted the localize-expr-in-attr branch April 1, 2022 18:24
@lit-robot lit-robot mentioned this pull request Apr 4, 2022
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.

[localize] transform mode doesn't handle template strings with quotes very well

2 participants