Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 33e2f1a

Browse files
committed
fixed code theming issue
1 parent 3899213 commit 33e2f1a

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

src/components/other/LiveCoder/components/LiveCoderReact/index.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import * as React from 'react';
22
import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live';
3-
import clsx from 'clsx';
43
import styles from './styles.module.css';
54
import { CodeSectionPropsInterface } from '../../index';
65
import ReactLiveScope from '@theme/ReactLiveScope';
6+
import { useEffect, useState } from 'react';
77

88
interface Props extends CodeSectionPropsInterface {}
99

1010
const LiveCoderReact: React.FC<Props> = (props) => {
1111
const { code, theme, transformCode } = props;
1212

13+
const [mounted, setMounted] = useState(false);
14+
// The Prism theme on SSR is always the default theme but the site theme
15+
// can be in a different mode. React hydration doesn't update DOM styles
16+
// that come from SSR. Hence force a re-render after mounting to apply the
17+
// current relevant styles. There will be a flash seen of the original
18+
// styles seen using this current approach but that's probably ok. Fixing
19+
// the flash will require changing the theming approach and is not worth it
20+
// at this point.
21+
useEffect(() => {
22+
setMounted(true);
23+
}, []);
24+
1325
return (
1426
<LiveProvider
27+
key={String(mounted)}
1528
code={code.replace(/\n$/, '')}
1629
transformCode={transformCode || ((code) => `${code};`)}
1730
theme={theme}

src/components/other/LiveCoder/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import LiveCoderReact from './components/LiveCoderReact';
44
import { PrismTheme } from 'prism-react-renderer';
55
import { useState } from 'react';
66
import LiveCodeNotFound from './components/LiveCodeNotFound';
7-
import FrameworkButton, {
8-
FrameworkButtonProps,
9-
} from './components/FrameworkButton';
107
import { FaReact, FaVuejs } from 'react-icons/all';
11-
import usePrismTheme from '../../../theme/hooks/usePrismTheme';
8+
import usePrismTheme from '@theme/hooks/usePrismTheme';
129
import PlainButton from '../../buttons/PlainButton';
10+
import FrameworkButton from './components/FrameworkButton';
1311

1412
type Props = {
1513
reactCode: string;

src/theme/hooks/usePrismTheme.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)