Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// https://github.com/threepointone/glamor/blob/master/docs/server.md
let glamorRenderStatic
try {
// $FlowFixMe just ignore glamor as we don't have it as a dep
glamorRenderStatic = require("glamor/server").renderStatic
}
catch (e) {
// skip glamor if not working
}
// Aprodite
// https://github.com/Khan/aphrodite#server-side-rendering
let aproditeRenderStatic
try {
// $FlowFixMe just ignore aprodite as we don't have it as a dep
aproditeRenderStatic = require("aphrodite").StyleSheetServer.renderStatic
}
catch (e) {
// skip aprodite if not working
}
// render body
let body
if (glamorRenderStatic) {
const glamorResult = glamorRenderStatic(() => props.renderBody())
renderToString(
function outputAphrodite(aphroditeApp, filename) {
const {css} = aphrodite.StyleSheetServer.renderStatic(aphroditeApp);
fs.writeFileSync(
path.join(__dirname, 'results', filename),
css.content,
'utf8'
);
}
.add('aphrodite (uber.css)', function() {
aphrodite.StyleSheetServer.renderStatic(uberApp.aphrodite);
})
.add('styletron (uber.css)', function() {
.add('aphrodite (all-unique)', function() {
aphrodite.StyleSheetServer.renderStatic(allUniqueApp.aphrodite);
})
.add('styletron (all-unique)', function() {
module.exports = (sheet, synthetic) => {
const keys = Object.keys(sheet);
const len = keys.length;
let first;
let middle;
let last;
let {css} = aphrodite.StyleSheetServer.renderStatic(() => {
let aphroditeStyles = aphrodite.StyleSheet.create(sheet);
for (let i = 0; i < len; i++) {
let className = aphrodite.css(aphroditeStyles[keys[i]]);
if (i === 0) {
first = className;
} else if (keys[i] === 'c1000') {
middle = className;
} else if (i === len - 1) {
last = className;
}
}
});
const styleElement = synthetic
? `<style data-aphrodite=""></style>`
: `<style data-aphrodite="">${css.content}</style>`;