-
-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Add keep_at_rules
option
#485
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
base: master
Are you sure you want to change the base?
Conversation
155e7b6
to
64161f7
Compare
CodSpeed Performance ReportMerging #485 will not alter performanceComparing Summary
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #485 +/- ##
==========================================
+ Coverage 88.05% 89.05% +0.99%
==========================================
Files 18 18
Lines 1993 2037 +44
==========================================
+ Hits 1755 1814 +59
+ Misses 238 223 -15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Great start! Definitely on the right track :) I left a few comments
css-inline/src/html/serializer.rs
Outdated
@@ -114,6 +127,22 @@ impl<'a> Sink<'a> { | |||
|
|||
serializer.start_elem(&element.name, &element.attributes, style_node_id)?; | |||
|
|||
// TODO this part is the one that I don't like the most |
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 am not 100% sure about this one, even though it is a sound approach.
The first thought that I have is that the least surprising thing would be to keep @
rules in their original places, instead of pushing everything into a single node. This won't work for external stylesheets, so we need to store them somewhere anyway.
On the other hand, this approach is better for performance, and probably it would not be super surprising for the user anyway if we put everything under one <style>
tag.
So, in the end, I am leaning towards this approach.
A few other notes:
- We can reduce the performance hit of checking each node name by having two versions of
serialize
- the first one will work as before this PR. The new one will check forhead
and once it is found, it will switch to the other version ofserialize
that won't check the tag name. At the top level we check ifat_rules
are present and then call one of these two versions - I think it should minimize the impact ashead
is usually in the very beginning of the nodes vector. - Are there cases when
head
is not present? Maybe in HTML fragments? seeinline_fragment
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.
btw, if the user chose to keep style
tags - I think we can only extract @
rule from link
, as the old style
tags will be around anyway
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's something I had no time to look closer into yet
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.
Given the current benchmark results, the performance hit is negligible, so we can skip this. For fragments, likely we can't really do it, as there is no regular HTML structure generally. Maybe we can return an error when the user sets an option to keep at rules, but uses inline_fragment
?
Hi @kamilzych Let me know if you need any assistance or if you plan to continue working on this PR. I'd be happy to help or take over in case if you don't plan to continue this PR. |
ffe46ee
to
c4adfc7
Compare
@Stranger6667 Hi! Apologies for lack of activity, I simply had no time, life happened I've just pushed a commit which addresses some of your comments. I'd love to finish the whole PR but I'm not sure when I have enough time to move this forward. |
Awesome! Thank you so much! :) I’ll be on vacation till the end of next week, but I’ll review the changes in any event :) Let’s see how it goes |
Amazing to see that we already have a working version! There are a few minor things left; there is no time pressure, so I'm just noting what is left to do, and maybe I'll push some changes to it in the next few evenings:
|
c4adfc7
to
fdfd7c8
Compare
As for the next steps, I think most of them are about adding new config option to bindings, so they compile. This flag is the same as others in terms of behavior, so it should be more or less straightforward. about the error, we can add an extra check to inline_fragment |
@@ -199,6 +201,9 @@ OPTIONS: | |||
|
|||
--keep-link-tags | |||
Keep "link" tags after inlining. | |||
|
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.
There is a small place above where this flag should be added too. The handle_boolean_flag function
Rel #265 (comment)