Skip to content

Commit 54f48c0

Browse files
committed
Prevent Suspense being rendering during SSR
Fixes #738 (again) Fixes #865 Avoids error https://reactjs.org/docs/error-decoder.html/?invariant=294
1 parent 2bbabb6 commit 54f48c0

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/ReactPlayer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import Player from './Player'
1010

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

13+
const IS_BROWSER = typeof window !== 'undefined' && window.document
1314
const SUPPORTED_PROPS = Object.keys(propTypes)
15+
16+
// Return null when rendering on the server
17+
// as Suspense is not supported yet
18+
const UniversalSuspense = IS_BROWSER ? Suspense : () => null
19+
1420
const customPlayers = []
1521

1622
export default class ReactPlayer extends Component {
@@ -158,11 +164,11 @@ export default class ReactPlayer extends Component {
158164
const attributes = this.getAttributes(url)
159165
return (
160166
<Wrapper ref={this.references.wrapper} style={{ ...style, width, height }} {...attributes}>
161-
<Suspense fallback={null}>
167+
<UniversalSuspense fallback={null}>
162168
{showPreview
163169
? this.renderPreview(url)
164170
: this.renderActivePlayer(url)}
165-
</Suspense>
171+
</UniversalSuspense>
166172
</Wrapper>
167173
)
168174
}

0 commit comments

Comments
 (0)