Skip to content

Commit

Permalink
fix: webpack loader issue with anti flicker script
Browse files Browse the repository at this point in the history
  • Loading branch information
designcise committed Nov 26, 2023
1 parent b194b18 commit f4c4f92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/AntiFlickerScript.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React, { memo } from 'react';

export default memo(function AntiFlickerScript({ theme, color }) {
const script = `(function(theme,root){root.classList.remove(\`'${Object.values(color).join("','")}'\`);root.classList.add(theme);root.style.colorScheme=theme;})('${theme}',document.firstElementChild)`;
return <script dangerouslySetInnerHTML={{ __html: script }} />
}, () => true);
8 changes: 2 additions & 6 deletions src/ThemeProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
'use client'

import React, { useEffect, useState, useCallback, memo } from 'react';
import React, { useEffect, useState, useCallback } from 'react';
import ThemeContext from './ThemeContext';
import { getPreference, setPreference, getColors } from './helper/theme.helper';
import AntiFlickerScript from './AntiFlickerScript';

const color = getColors();

const AntiFlickerScript = memo(function Script({ theme, color }) {
const script = (() => `(function(theme,root){root.classList.remove(\`'${Object.values(color).join("','")}'\`);root.classList.add(theme);root.style.colorScheme=theme;})('${theme}',document.firstElementChild)`)();
return <script dangerouslySetInnerHTML={{ __html: script }} />
}, () => true);

export default function ThemeProvider({
children,
storageKey,
Expand Down

0 comments on commit f4c4f92

Please sign in to comment.