Skip to content

Commit

Permalink
Inject css.global and css.keyframes SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Duarte committed Sep 10, 2020
1 parent 2aa55e7 commit 5d217c4
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 119 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export const createCss = <T extends TConfig>(
: createServerToString(sheets, config.breakpoints, cssClassnameProvider);

let themeToString = createThemeToString(classPrefix, sheets.__variables__);
let keyframesToString = createKeyframesToString(sheets[MAIN_BREAKPOINT_ID]);
let keyframesToString = createKeyframesToString(sheets.__keyframes__);
const compose = (...atoms: IAtom[]): IComposedAtom => {
const map = new Map<string, IAtom>();
composeIntoMap(map, atoms);
Expand Down Expand Up @@ -649,7 +649,9 @@ export const createCss = <T extends TConfig>(
cssInstance.getStyles = (cb: any) => {
// tslint:disable-next-line
for (let sheet in sheets) {
sheets[sheet].cssRules.length = 0;
if (sheet !== '__keyframes__') {
sheets[sheet].cssRules.length = 0;
}
}
if (baseTokens) {
sheets.__variables__.insertRule(baseTokens);
Expand Down Expand Up @@ -683,6 +685,7 @@ export const createCss = <T extends TConfig>(
},
[
`/* STITCHES:__variables__ */\n${sheets.__variables__.cssRules.join('\n')}`,
`/* STITCHES:__keyframes__ */\n${sheets.__keyframes__.cssRules.join('\n')}`,
`/* STITCHES */\n${sheets[MAIN_BREAKPOINT_ID].cssRules.join('\n')}`,
]
),
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const createSheets = (env: any, screens: IBreakpoints = {}) => {

return {
tags,
sheets: ['__variables__', MAIN_BREAKPOINT_ID]
sheets: ['__variables__', '__keyframes__', MAIN_BREAKPOINT_ID]
.concat(Object.keys(screens))
.reduce<{ [key: string]: ISheet }>((aggr, key, index) => {
let style = existingStyles[index];
Expand All @@ -175,7 +175,7 @@ export const createSheets = (env: any, screens: IBreakpoints = {}) => {

return {
tags,
sheets: ['__variables__', MAIN_BREAKPOINT_ID]
sheets: ['__variables__', '__keyframes__', MAIN_BREAKPOINT_ID]
.concat(Object.keys(screens))
.reduce<{ [key: string]: ISheet }>((aggr, key) => {
aggr[key] = enhanceSheet({
Expand Down
Loading

0 comments on commit 5d217c4

Please sign in to comment.