-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Custom style tag #5639
Custom style tag #5639
Conversation
I'm not sure why some tests are failing.
Another test that is failing is: Can someone please help? |
@benmccann I now added the noop-parameter to all tests. |
@ivanhofer thank you for making the change. Usually we're more reluctant to merge a new feature if it increases the output size for the base case. is it possible to support this without adding extra code for users that does not need this feature? |
Hi @tanhauhau, For projects, that use the compiler option For projects that use I will check if there is a possibility to decrease the generated output for projects using |
@tanhauhau I just managed to decrease the amount of added code to 8 byte.
Are these changes good for you? What do you think? PS: I will later revert my changes to the tests, to make them work again. |
@tanhauhau my final analysis on bundle size using the official starter template without changes is:
When using When using
I cloned the As you can see the output with the changes in this branch become less than the output from the I hope that the size-savings by using multiple components justifies the additional size for a single component. |
I managed to strip another few bytes from the output size:
As you can see, now the output for a bundle with 3 components is smaller than before. I now reduced the output of the add_css function of each component to a minimum. I moved the "svelte-" and "-style" parts from the id to the shared method. At first glance it looks a bit odd, but reduces the bundle size by a few more bytes. |
src/runtime/internal/Component.ts
Outdated
export function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { | ||
const parent_component = current_component; | ||
set_current_component(component); | ||
|
||
const prop_values = options.props || {}; | ||
|
||
const $$: T$$ = component.$$ = { | ||
...component.$$, |
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 understand that doing this was to make the code size for the base case unchanged.
but i'm ambivalent of doing this.
what do you think @Conduitry
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 think the only option without additional code for the base output is to rewrite the function add_css_to_component
to this:
export function add_css_to_component(component, add_css, options) {
component.customStyleTag = options.customStyleTag || current_component && current_component.customStyleTag;
add_css(component.customStyleTag || document.head);
}
But then it is a "hidden" property on the class itself.
I chose the option to include it in the $$ context object because that's why the context object exists.
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.
another solition could be to save the information in a variable like the current_component:
let appendStylesTo = document.head
export function add_css_to_component(add_css, options) {
if (options.customStyleTag) appendStylesTo = options.customStyleTag
add_css(appendStylesTo);
}
@tanhauhau I now removed When using
The output size with this PR applied reduces by ~100bytes for each component comparing the current implementation on master. I was looking into writing tests for |
closing in favor of #5870, which is a clean re-implementation of this PR |
issue: #3940
I added an option to allow to specify a Element where the styles should be applied. Currently the styles are always appended to document.head.
This PR is useful for a svelte-application that is rendered inside a shadow-dom. Because of the style-encapsulation that come with shadow-doms, the application will not have any styles when rendered inside a shadow-dom.
Please let me know if you have any concern with this approach?