Skip to content

[Web] Static Theme - useCSSVariable - We couldn't find your variable during SSR #537

@denniske

Description

@denniske

What happened?

When using a color variable defined in a static theme this error is shown:

WARN Uniwind - We couldn't find your variable --color-gold-50. Make sure it's used at least once in your className, or define it in a static theme as described in the docs: https://docs.uniwind.dev/api/use-css-variable

I got this error on web but it might occur on iOS/Android also.

Steps to Reproduce

  1. Create a static theme in globals.css

@theme static {
    /* Base Tailwind colors */
    --color-black: #000;
    --color-white: #fff;

    /* Custom gold palette */
    --color-gold-50: #FFFCF5;
    --color-gold-100: #ffebc7;
    --color-gold-200: #ffdf8f;
    --color-gold-300: #ffd24d;
    --color-gold-400: #ffcb1f;
    --color-gold-500: #f9b806;
    --color-gold-600: #dea002;
    --color-gold-700: #b77f06;
    --color-gold-800: #92680c;
    --color-gold-900: #785b0d;
    --color-gold-950: #453802;
}

  1. Use one of the colors in useCSSVariable

export default function HomeScreen() {
    const colorGold50 = useCSSVariable('--color-gold-50') as string;
    console.log('colorGold50', colorGold50);

    return (
        <SafeAreaView>
            <View className="p-5 bg-green-300">
                <Text className="text-foreground">Coffee</Text>
            </View>
        </SafeAreaView>
    );
}

Snack or Repository Link

https://github.com/denniske/uniwind-theme-variable-repro

Uniwind version

1.6.5

React Native Version

0.81.5

Platforms

Web

Expo

Yes

Additional information

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions