Skip to content

Commit

Permalink
Revert removal of browsers only
Browse files Browse the repository at this point in the history
Signed-off-by: Josh-Cena <[email protected]>
  • Loading branch information
Josh-Cena committed Sep 2, 2021
1 parent 18e3fc0 commit 85e0f2c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/docusaurus-plugin-debug/src/theme/DebugJsonView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@
*/

import React from 'react';
import ReactJson from 'react-json-view';
import BrowserOnly from '@docusaurus/BrowserOnly';
import type {Props} from '@theme/DebugJsonView';
import type {ReactJsonViewProps} from 'react-json-view';

// avoids "react-json-view" to display "root"
const RootName = false;

// Seems ReactJson does not work with SSR
// https://github.com/mac-s-g/react-json-view/issues/121
const BrowserOnlyReactJson = (props: ReactJsonViewProps) => {
return (
<BrowserOnly>
{() => {
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
const ReactJson = require('react-json-view').default;
return <ReactJson {...props} />;
}}
</BrowserOnly>
);
};

function DebugJsonView({src, collapseDepth}: Props): JSX.Element {
return (
<ReactJson
<BrowserOnlyReactJson
// Type defined by react-json-view
// eslint-disable-next-line @typescript-eslint/ban-types
src={src as object}
Expand Down

0 comments on commit 85e0f2c

Please sign in to comment.