-
Notifications
You must be signed in to change notification settings - Fork 392
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
feat(engine): inline styles to support native shadow #540
Conversation
Benchmark resultsBase commit: lwc-engine-benchmark
|
556ee02
to
d3ed20f
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
@pmdartus this is now ready to roll! you can base your branch for compiler off this branch. |
} else { | ||
// native shadow in place, we need to act accordingly by using the `:host` | ||
// selector, and an empty shadow selector since it is not really needed | ||
const textContent = style(':host', ''); |
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.
After working #637, replacing the token there will not work. We need to duplicate the CSS rule to make this work.
// Original
:host(.active) {}
// Transformed
[host-token].active {}
// With the :host replace at runtime
:host.active {}
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark-ie11
|
7576413
to
aae9989
Compare
Benchmark resultsBase commit: lwc-engine-benchmark-ie11
|
Benchmark resultsBase commit: lwc-engine-benchmark-ie11
|
aae9989
to
8eab8c6
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
Please ignore my accidental approval |
Benchmark resultsBase commit: lwc-engine-benchmark
|
I ok with both approaches. |
@diervo, can you comment here? |
|
||
// Inserting a placeholder for <style> to guarantee that native and synthetic shadow markup | ||
// are identical. | ||
styleElement = getCachedStyleElement(process.env.NODE_ENV !== 'production' ? `/* synthetic style for component ${shadowSelector} */` : ''); |
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.
Let's remove this for now.
@@ -133,6 +113,10 @@ export function evaluateTemplate(vm: VM, html: Template): Array<VNode|null> { | |||
} | |||
const vnodes = html.call(undefined, api, component, cmpSlots, context.tplCache); | |||
|
|||
const { styleVNode } = context; | |||
// inserting the style tag at the top always | |||
ArrayUnshift.call(vnodes, isUndefined(styleVNode) ? null : styleVNode); |
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 a surrounding branch to not do the unshift if the styleVNode is undefined.
fix(engine): integration test feat(compiler): inline styles to support native shadow (#691) Add compiler changes required for the shadow DOM injection of the stylesheet. The CSS transformer now attach to the template an object with 3 properties: * `hostAttribute` - the attribute to apply to the host element * `shadowAttribute` - the attribute to apply to the shadow elements * `factory` - a function accepting a `hostSelector` and a `shadowSelector` to apply to the styles. Note the difference in naming, `hostAttribute` is the attribute name, while the factory excepts a selector `[attr]`. This changes is necessary to be able to generate at runtime both native and synthetic shadow compatible stylesheets. Changes: * Make changes to the CSS transform, it nows accepts 2 parameters a `hostSelector` and a `shadowSelector`. * Update the compiler produce the new `Stylesheet` format for runtime consumption * Update references to `styleToken` in the engine code to `styleAttribute` to better match the actual purpose * [ ] Yes * [X] No - as long as nobody is invoking the CSS transform manually since it's signature changed fix: removed file missed during squash
ec5f10a
to
bd13dbd
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
Details
template.style
can be a function that when invoked, returns the inline stylestyle
element is always the first element in the shadow if the rendered template hasstyle
propertyThis is PR is compatible with the existing compilation, it supports both mechanism. Eventually, once the compiler updates, we can remove the forking logic in tests and update template.ts to always rely on the style function instead of the template to extract tokens.
Does this PR introduce a breaking change?