mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-14 00:32:47 +02:00
fix(v2): render correct syntax theme for current website theme (#2150)
This commit is contained in:
parent
92c68ed742
commit
167f71a654
2 changed files with 28 additions and 0 deletions
|
@ -24,7 +24,20 @@ export default ({children, className: languageClassName, metastring}) => {
|
||||||
themeConfig: {prism = {}},
|
themeConfig: {prism = {}},
|
||||||
},
|
},
|
||||||
} = useDocusaurusContext();
|
} = useDocusaurusContext();
|
||||||
|
|
||||||
const [showCopied, setShowCopied] = useState(false);
|
const [showCopied, setShowCopied] = useState(false);
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
// The Prism theme on SSR is always the default theme but the site theme
|
||||||
|
// can be in a different mode. React hydration doesn't update DOM styles
|
||||||
|
// that come from SSR. Hence force a re-render after mounting to apply the
|
||||||
|
// current relevant styles. There will be a flash seen of the original
|
||||||
|
// styles seen using this current approach but that's probably ok. Fixing
|
||||||
|
// the flash will require changing the theming approach and is not worth it
|
||||||
|
// at this point.
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const target = useRef(null);
|
const target = useRef(null);
|
||||||
const button = useRef(null);
|
const button = useRef(null);
|
||||||
let highlightLines = [];
|
let highlightLines = [];
|
||||||
|
@ -70,6 +83,7 @@ export default ({children, className: languageClassName, metastring}) => {
|
||||||
return (
|
return (
|
||||||
<Highlight
|
<Highlight
|
||||||
{...defaultProps}
|
{...defaultProps}
|
||||||
|
key={mounted}
|
||||||
theme={prismTheme}
|
theme={prismTheme}
|
||||||
code={children.trim()}
|
code={children.trim()}
|
||||||
language={language}>
|
language={language}>
|
||||||
|
|
|
@ -31,7 +31,20 @@ export default ({
|
||||||
themeConfig: {prism = {}},
|
themeConfig: {prism = {}},
|
||||||
},
|
},
|
||||||
} = useDocusaurusContext();
|
} = useDocusaurusContext();
|
||||||
|
|
||||||
const [showCopied, setShowCopied] = useState(false);
|
const [showCopied, setShowCopied] = useState(false);
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
// The Prism theme on SSR is always the default theme but the site theme
|
||||||
|
// can be in a different mode. React hydration doesn't update DOM styles
|
||||||
|
// that come from SSR. Hence force a re-render after mounting to apply the
|
||||||
|
// current relevant styles. There will be a flash seen of the original
|
||||||
|
// styles seen using this current approach but that's probably ok. Fixing
|
||||||
|
// the flash will require changing the theming approach and is not worth it
|
||||||
|
// at this point.
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const target = useRef(null);
|
const target = useRef(null);
|
||||||
const button = useRef(null);
|
const button = useRef(null);
|
||||||
let highlightLines = [];
|
let highlightLines = [];
|
||||||
|
@ -88,6 +101,7 @@ export default ({
|
||||||
return (
|
return (
|
||||||
<Highlight
|
<Highlight
|
||||||
{...defaultProps}
|
{...defaultProps}
|
||||||
|
key={mounted}
|
||||||
theme={prismTheme}
|
theme={prismTheme}
|
||||||
code={children.trim()}
|
code={children.trim()}
|
||||||
language={language}>
|
language={language}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue