Skip to content

Commit 53d9e53

Browse files
committed
Fixing problem with server side rendering failing
1 parent 2d06b02 commit 53d9e53

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

src/components/Chip/index.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
import React, { useEffect, useState } from 'react';
22

3+
import BrowserOnly from '@docusaurus/BrowserOnly';
4+
5+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
6+
37
export default function Chip ({ label, color }) {
48
const [isDarkTheme, setIsDarkTheme] = useState(false);
59

6-
useEffect(() => {
7-
setIsDarkTheme(document.documentElement.getAttribute('data-theme') === 'dark');
8-
}, [document.documentElement.getAttribute('data-theme')]);
10+
if (ExecutionEnvironment.canUseDOM) {
11+
useEffect(() => {
12+
setIsDarkTheme(document.documentElement.getAttribute('data-theme') === 'dark');
13+
}, [document.documentElement.getAttribute('data-theme')]);
14+
}
915

1016
const backgroundColor = isDarkTheme
1117
? `var(--ifm-color-chip-${color ?? 'blue'}-dark)` // Dark theme background color
1218
: `var(--ifm-color-chip-${color ?? 'blue'}-light)`; // Light theme background color
1319

1420
return (
15-
<div
16-
style={{
17-
display: 'inline-flex',
18-
alignItems: 'center',
19-
justifyContent: 'center',
20-
backgroundColor,
21-
borderRadius: '16px',
22-
height: '24px',
23-
padding: '4px 8px',
24-
marginX: '2px',
25-
fontSize: '14px'
26-
}}
27-
>
28-
{label}
29-
</div>
21+
<BrowserOnly>{() =>
22+
<div
23+
style={{
24+
display: 'inline-flex',
25+
alignItems: 'center',
26+
justifyContent: 'center',
27+
backgroundColor,
28+
borderRadius: '16px',
29+
height: '24px',
30+
padding: '4px 8px',
31+
marginX: '2px',
32+
fontSize: '14px'
33+
}}
34+
>
35+
{label}
36+
</div>
37+
}
38+
</BrowserOnly>
3039
);
3140
};

src/components/Image/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import React from 'react'
22

33
import s from './index.module.css'
44

5+
import BrowserOnly from '@docusaurus/BrowserOnly';
6+
57
export default function Image(props) {
68
const { src, alt, style, width = '100%', centered = false} = props
79
const imageStyle = { ...style, width }
810

911
return (
10-
<div className={centered ? s.centered : ''}>
11-
<img src={src} alt={alt} className={s.default} style={imageStyle} />
12-
</div>
12+
<BrowserOnly>{() =>
13+
<div className={centered ? s.centered : ''}>
14+
<img src={src} alt={alt} className={s.default} style={imageStyle} />
15+
</div>
16+
}
17+
</BrowserOnly>
1318
)
1419
}

0 commit comments

Comments
 (0)