Skip to content

Commit

Permalink
fix incorrect color mode (#2596)
Browse files Browse the repository at this point in the history
  • Loading branch information
isstuev authored Feb 28, 2025
1 parent 540d95e commit a6d05af
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/contexts/chakra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import {
import type { ChakraProviderProps } from '@chakra-ui/react';
import React from 'react';

import { get, NAMES } from 'lib/cookies';
import theme from 'theme/theme';

interface Props extends ChakraProviderProps {
cookies?: string;
}

export function ChakraProvider({ cookies, children }: Props) {
// When a cookie header is present, cookieStorageManagerSSR looks for a "chakra-ui-color-mode" cookie.
// If it doesn’t find one, it doesn’t consider theme’s initialColorMode. Instead, it is defaulting to light mode
// So we need to use localStorageManager instead of cookieStorageManagerSSR to get the correct default color mode
const colorModeManager =
typeof cookies === 'string' ?
cookieStorageManagerSSR(typeof document !== 'undefined' ? document.cookie : cookies) :
localStorageManager;
typeof cookies === 'string' && get(NAMES.COLOR_MODE, cookies) ?
cookieStorageManagerSSR(typeof document !== 'undefined' ? document.cookie : cookies) :
localStorageManager;

return (
<ChakraProviderDefault colorModeManager={ colorModeManager } theme={ theme }>
Expand Down

0 comments on commit a6d05af

Please sign in to comment.