diff --git a/packages/utilities/getCSSVarValue.ts b/packages/utilities/getCSSVarValue.ts index 1c59d7d82..15014e951 100644 --- a/packages/utilities/getCSSVarValue.ts +++ b/packages/utilities/getCSSVarValue.ts @@ -1,10 +1,14 @@ const getCSSVarValue = cssVar => { - if (document.documentElement !== null) { - // Get the content between the parentheses in "var()" - // and split the args from a string to an array - const cssVarArgsString = cssVar.match(/\(([^)]+)\)/)[1]; - const cssVarArgs = cssVarArgsString.replace(/\s/g, "").split(","); + // Get the content between the parentheses in "var()" + // and split the args from a string to an array + const cssVarArgsString = cssVar.match(/\(([^)]+)\)/)[1]; + const cssVarArgs = cssVarArgsString.replace(/\s/g, "").split(","); + if (typeof window === "undefined") { + return cssVarArgs[1]; + } + + if (document?.documentElement !== null) { // If there's a custom property defined on :root (), return that. // Otherwise, return the fallback value. return (