Skip to content

Commit

Permalink
refactor(core): updated styleSheet initialization for SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
hirotomoyamada committed Oct 16, 2023
1 parent f170544 commit f4c37a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-moose-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@yamada-ui/core': patch
---

Updated `styleSheet` initialization for SSR.
8 changes: 5 additions & 3 deletions packages/core/src/styles/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import {
CSSObject,
} from '@emotion/react'
import { StyleSheet } from '@emotion/sheet'
import { isArray, isObject, isString, Dict } from '@yamada-ui/utils'
import { isArray, isObject, isString, Dict, createdDom } from '@yamada-ui/utils'
import { ColorMode, css } from '../css'
import { ThemeToken } from '../theme'
import { StyledTheme } from '../theme.types'
import { Transform } from './config'

const styleSheet = new StyleSheet({ key: 'css', container: document.head })
const styleSheet = createdDom()
? new StyleSheet({ key: 'css', container: document.head })
: undefined

const directions: Record<string, string> = {
'to-t': 'to top',
Expand Down Expand Up @@ -144,7 +146,7 @@ export const generateAnimation: Transform = (value, theme) => {
} = css(transformAnimationValue(value))(theme)
const { name, styles } = emotionKeyframes(keyframes)

styleSheet.insert(styles)
styleSheet?.insert(styles)

return `${name} ${animationDuration} ${animationTimingFunction} ${delay} ${iterationCount} ${direction} ${fillMode} ${playState}`
} else if (value.includes(',')) {
Expand Down

0 comments on commit f4c37a4

Please sign in to comment.