Skip to content

Commit 93699ba

Browse files
committed
fix: add SSR check before parsing and allowing CSSVariables
due to accessing window requirement resolves #1805
1 parent a5990e8 commit 93699ba

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

packages/shared/src/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@ export const flushCalls = <T extends AnyFn>(
8888
queue: Set<T>,
8989
...args: Parameters<T>
9090
) => flush(queue, fn => fn(...args))
91+
92+
// For server-side rendering: https://github.com/react-spring/zustand/pull/34
93+
// Deno support: https://github.com/pmndrs/zustand/issues/347
94+
95+
export const isSSR = () =>
96+
typeof window === 'undefined' ||
97+
!window.navigator ||
98+
/ServerSideRendering|^Deno\//.test(window.navigator.userAgent)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as G from './globals'
2-
import { is } from './helpers'
2+
import { is, isSSR } from './helpers'
33
import { cssVariableRegex } from './regexs'
44

55
// Not all strings can be animated (eg: {display: "none"})
@@ -8,7 +8,8 @@ export function isAnimatedString(value: unknown): value is string {
88
is.str(value) &&
99
(value[0] == '#' ||
1010
/\d/.test(value) ||
11-
cssVariableRegex.test(value) ||
11+
// Do not identify a CSS variable as an AnimatedString if its SSR
12+
(!isSSR() && cssVariableRegex.test(value)) ||
1213
value in (G.colors || {}))
1314
)
1415
}

packages/shared/src/variableToRgba.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isSSR } from './helpers'
12
import { cssVariableRegex } from './regexs'
23

34
/**
@@ -14,7 +15,7 @@ import { cssVariableRegex } from './regexs'
1415
export const variableToRgba = (input: string): string => {
1516
const [token, fallback] = parseCSSVariable(input)
1617

17-
if (!token) {
18+
if (!token || isSSR()) {
1819
return input
1920
}
2021

0 commit comments

Comments
 (0)