Skip to content

Commit 8eefe57

Browse files
committed
fix: disable ssr in function inspect
1 parent f968a42 commit 8eefe57

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

src/components/DataTypes/Function.tsx

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { Box } from '@mui/material'
1+
/**
2+
* Use NoSsr on function value.
3+
* Because in Next.js SSR, the function will be translated to other type
4+
*/
5+
import { Box, NoSsr } from '@mui/material'
26
import type React from 'react'
37

48
import { useJsonViewerStore } from '../../stores/JsonViewerStore'
@@ -39,7 +43,7 @@ const rb = '}'
3943

4044
export const PreFunctionType: React.FC<DataItemProps<Function>> = (props) => {
4145
return (
42-
<>
46+
<NoSsr>
4347
<DataTypeLabel dataType='function'/>
4448
<Box
4549
component='span' className='data-function-start'
@@ -50,42 +54,46 @@ export const PreFunctionType: React.FC<DataItemProps<Function>> = (props) => {
5054
{functionName(props.value)}
5155
{' '}{lb}
5256
</Box>
53-
</>
57+
</NoSsr>
5458
)
5559
}
5660

5761
export const PostFunctionType: React.FC<DataItemProps<Function>> = () => {
5862
return (
59-
<Box component='span' className='data-function-end'>
60-
{rb}
61-
</Box>
63+
<NoSsr>
64+
<Box component='span' className='data-function-end'>
65+
{rb}
66+
</Box>
67+
</NoSsr>
6268
)
6369
}
6470

6571
export const FunctionType: React.FC<DataItemProps<Function>> = (props) => {
6672
const functionColor = useJsonViewerStore(store => store.colorspace.base05)
6773
return (
68-
<Box
69-
className='data-function'
70-
sx={{
71-
display: props.inspect ? 'block' : 'inline-block',
72-
pl: props.inspect ? 2 : 0,
73-
color: functionColor
74-
}}
75-
>
76-
{props.inspect
77-
? functionBody(props.value)
78-
: (
79-
<Box component='span' className='data-function-body'
80-
onClick={() => props.setInspect(true)}
81-
sx={{
82-
'&:hover': { cursor: 'pointer' }
83-
}}
84-
>
85-
...
86-
</Box>
87-
)
88-
}
89-
</Box>
74+
<NoSsr>
75+
<Box
76+
className='data-function'
77+
sx={{
78+
display: props.inspect ? 'block' : 'inline-block',
79+
pl: props.inspect ? 2 : 0,
80+
color: functionColor
81+
}}
82+
>
83+
{props.inspect
84+
? functionBody(props.value)
85+
: (
86+
<Box component='span' className='data-function-body'
87+
onClick={() => props.setInspect(true)}
88+
sx={{
89+
'&:hover': { cursor: 'pointer' }
90+
}}
91+
>
92+
...
93+
</Box>
94+
)
95+
}
96+
</Box>
97+
</NoSsr>
9098
)
9199
}

0 commit comments

Comments
 (0)