-
Notifications
You must be signed in to change notification settings - Fork 399
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
refactor(template-compiler): remove apis template fn argument #2758
Conversation
return [ | ||
t.variableDeclaration('const', [ | ||
t.variableDeclarator( | ||
t.objectPattern( | ||
Object.keys(codeGen.usedApis).map((name) => | ||
t.assignmentProperty(t.identifier(name), codeGen.usedApis[name]) | ||
) | ||
), | ||
t.identifier(RENDER_API) | ||
), | ||
]), | ||
]; |
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.
From a tree-shaking perspective, it is probably better to export each render API independently. This would also remove the need to use an object spread at the top of each generated template. That said I am wondering if the tree-shaking benefits are outweighed by the increased output size for AMD.
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.
It also adds some unnecessary boilerplate in compat mode:
lwc.renderApi._ES5ProxyType ? lwc.renderApi.get("d") : lwc.renderApi.d
That said I am wondering if the tree-shaking benefits are outweighed by the increased output size for AMD.
I don't understand this. Could you explain?
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.
That said I am wondering if the tree-shaking benefits are outweighed by the increased output size for AMD.
I don't understand this. Could you explain?
Good catch @nolanlawson. I was mistaken, there is no increase in AMD module size. I was under the impression that using named imports would negatively impact the AMD module size by adding new entries in the dependency list (the first argument of the define
function). But it's wrong, the list contains the dependency module names and not the named imports for each dependency.
import { createVElement, createVText, createVComponent } from 'lwc';
createVElement();
createVText();
createVComponent();
define(['lwc'], (function (lwc) { 'use strict';
lwc.createVElement();
lwc.createVText();
lwc.createVComponent();
}));
I second PM's comment about tree-shaking. That would be especially important for the off-core (e.g. B2C) scenario, where a page might have a handful of LWC components that only use a few functions from the renderApi. It would be great if we could tree-shake out all the rest. I do wonder, though, if we are overloading the import { text, html } from `@lwc/renderer` The tricky part is that the |
I used to share the same feeling, but at the end of the day, those named exports are injected at compile time. Adding an indirection like |
25f64ec
to
798a40b
Compare
closed in favor of #2781 |
Details
This PR exposes the renderApi into the
lwc
module, so we can remove the$api
argument in the template function of the module in favor of hoisting the used apis outside the template function.The changes on this PR are required for #2688.
Commits:
Note: As part of this PR, I noticed two things:
compileToFunction
is only used for test, and only 4 tests, opened refactor(template-compiler): remove compileToFunction #2757 to remove it.Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?
GUS work item