-
Notifications
You must be signed in to change notification settings - Fork 68
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
Rehydration #36
Comments
Also I created a small blog post on this topic: https://engineering.hellofresh.com/the-css-in-js-battle-89c34a7a83ea |
Thanks for linking to these. I think this lib had a ton of potential, but needs hydration/vendor prefixes to be viable for my use case anyway. :( |
If anyone comes across this issue, I wrote a simple rehydration script if you're using a fork of cxs like I am: export function hydrateCss() {
if (typeof document === 'undefined') {
return
}
const styleElement = document.getElementById(
STYLE_ID
) as HTMLStyleElement
if (styleElement === null) {
return
}
const sheet = styleElement.sheet!
const rules = sheet.cssRules
const maxLength = rules.length - 1
for (let index = maxLength; index >= 0; index--) {
const rule = rules[index]
const className = rule.cssText.split(' ')[0].slice(1)
const declaration = rule.cssText.slice(
rule.cssText.indexOf('{') + 2,
rule.cssText.lastIndexOf('}') - 2
)
const [key, value] = declaration.split(': ')
const cacheKey = hash(key + value)
insert(rule.cssText)
cache[cacheKey] = className
sheet.deleteRule(index)
}
} It only handles simple rules right now, but I plan to expand it to handle nested selectors and media queries when I get a chance. |
Hey guys, was wondering why you guys don't implement client rehydration like Aphrodite and Glamor do?
Isn't this a bit wasteful, since all the CSS is already generated?
The text was updated successfully, but these errors were encountered: