Skip to content

Commit

Permalink
fix(v2): render children in BrowserOnly after client is ready (#4935)
Browse files Browse the repository at this point in the history
* fix(v2): render children in BrowserOnly after client is ready

* Fix fallback issue
  • Loading branch information
lex111 committed Jun 9, 2021
1 parent 869f4bf commit d81d43c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/docusaurus/src/client/exports/BrowserOnly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import ExecutionEnvironment from './ExecutionEnvironment';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

function BrowserOnly({
children,
Expand All @@ -15,11 +15,13 @@ function BrowserOnly({
children?: () => JSX.Element;
fallback?: JSX.Element;
}): JSX.Element | null {
if (!ExecutionEnvironment.canUseDOM || children == null) {
return fallback || null;
const {isClient} = useDocusaurusContext();

if (isClient && children != null) {
return <>{children()}</>;
}

return <>{children()}</>;
return fallback || null;
}

export default BrowserOnly;

0 comments on commit d81d43c

Please sign in to comment.