-
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: simplify style logic in template compiler #314
Conversation
29300d9
to
33236d3
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
@@ -76,7 +76,7 @@ export interface VNodeData { | |||
props?: Props; | |||
attrs?: Attrs; | |||
class?: Classes; | |||
style?: VNodeStyle; | |||
style?: VNodeStyle | string; |
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.
we should mark this as a difference since this file is copied and modified from snabbdom, so we know when copying the new one.
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.
... @pmdartus
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.
additionally, we can expand this type in LWC only.
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.
We will fix this in an upcoming PR when removing the engine registry.
style[name] = cur; | ||
} | ||
if (cur !== (oldStyle as VNodeStyle)[name]) { | ||
style.setProperty(name, cur); |
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 is code copied from snabbdom (mostly). I wonder why did they use style[name] = cur
instead of setProperty
. was it because of the camelCase?
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.
Yes the setProperty
accepts the kebab-case version of it. While the direct set on the object accepts the camelCase.
I think they want to privilege the camelCase approach because of the developer ergonomic:
// camelCase
h('span', {
style: {
border: '1px solid #bada55',
fontWeight: 'bold'
}
}, 'Say my name, and every colour illuminates');
// kebab-case
h('span', {
style: {
border: '1px solid #bada55',
'font-weight': 'bold'
}
}, 'Say my name, and every colour illuminates');
But because we don't allow objects for styles, we don't have to deal with the camelCase.
I still don't trust BEST results. Instead of improving, it is now slower on append operation, which is weird. /cc @diervo |
@caridy you only say you don’t trust best when you don’t agree with the results. I believe using setAtribute is quite expensive compared with assigned it directly so I can understand why the changes really don’t do much |
It appears that FF and IE11 are (15%) slower when using |
Benchmark resultsBase commit: lwc-engine-benchmark
|
@caridy Ready for a second pass of review. |
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'm ok with this now, but I still don't understand why BEST is saying that this is taking 16% more time on update. /cc @diervo
@@ -44,14 +41,8 @@ function updateStyle(oldVnode: VNode, vnode: VNode) { | |||
|
|||
for (name in newStyle) { | |||
const cur = newStyle[name]; |
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.
Add comment here.
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
This PR is now ready to be merged. Waiting for master to stabilize and the new compiler to get deployed before merging. |
let's roll @pmdartus |
Details
setProperty
when patching style.Fix #227
Does this PR introduce a breaking change?