Skip to content

Commit

Permalink
Prevent Suspense being rendering during SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
albanqoku committed Apr 28, 2020
1 parent 2b74a89 commit beb4131
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import Player from './Player'

const Preview = lazy(() => import('./Preview'))

const IS_BROWSER = typeof window !== 'undefined' && window.document
const SUPPORTED_PROPS = Object.keys(propTypes)

// Return null when rendering on the server
// as Suspense is not supported yet
const UniversalSuspense = IS_BROWSER ? Suspense : () => null

const customPlayers = []

export default class ReactPlayer extends Component {
Expand Down Expand Up @@ -158,11 +164,11 @@ export default class ReactPlayer extends Component {
const attributes = this.getAttributes(url)
return (
<Wrapper ref={this.references.wrapper} style={{ ...style, width, height }} {...attributes}>
<Suspense fallback={null}>
<UniversalSuspense fallback={null}>
{showPreview
? this.renderPreview(url)
: this.renderActivePlayer(url)}
</Suspense>
</UniversalSuspense>
</Wrapper>
)
}
Expand Down

0 comments on commit beb4131

Please sign in to comment.