-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
SX: refactor 'injectRuntimeStyles' #1579
Labels
help wanted
Extra attention is needed
Comments
mrtnzlml
added a commit
that referenced
this issue
Apr 3, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
Apr 10, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
Apr 14, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
Apr 16, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
May 8, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
May 11, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
Jun 8, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
Jun 19, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
Jun 23, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
mrtnzlml
added a commit
that referenced
this issue
Jun 23, 2022
I have these changes sitting locally for a very long time, and it's time to offload them. The idea behind the styles rehydration is very simple: we collect all existing styles from `<style data-adeira-sx />` (once) and use this information later for deciding whether the styles should be injected or not (this is what I call rehydration). The difference from the current solution is that we do it only once and we don't have to go through all the styles everytime there is something to inject. Motivation for this change is performance: this should significantly improve the runtime style perf + be much easier to deal with (for example, we are basically brute-forcing @at rules and pseudo rules now). Note: this is just a partial solution, there are other changes coming (custom styles printer and @at nodes/pseudo nodes optimization). Related issue: #1579
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Function
injectRuntimeStyles
is currently wildly ineffective and kinda broken.How it works now
We call
injectRuntimeStyles
everytimesx.create({ … })
is called at runtime (in a browser context). This function tries to findstyle[data-adeira-sx]
HTML tag and it tries to inject there the styles fromsx.create
. It also tries to avoid adding already existing CSS classes but it does a fairly bad job (basically only simple rules are supported). Moreover, this check is performed for every single CSS class.You can check the problem by running the following code in a browser console (Firefox) and checking the massive output:
You should be able to see many duplicates caused by incorrectly (or rather inefficiently) injecting
StyleCollectorAtNode
andStyleCollectorPseudoNode
.How it should work
SX should inject only runtime styles that do not exist yet in
style[data-adeira-sx]
and each CSS class should be added only once. There are 2 ways how we can do this:rehydrate
the CSS classes (inspired by Aphrodite: https://github.com/Khan/aphrodite#server-side-rendering)The text was updated successfully, but these errors were encountered: