From e85059d808aeabaa515c54f123336eeaf4fd344c Mon Sep 17 00:00:00 2001 From: Wesley Luyten Date: Fri, 19 Apr 2024 11:13:05 -0500 Subject: [PATCH] feat!: enable Suspense by default BREAKING CHANGES: enable Suspense by default, remove environment checks --- src/ReactPlayer.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ReactPlayer.js b/src/ReactPlayer.js index 8ea69acf..fa1ae2f0 100644 --- a/src/ReactPlayer.js +++ b/src/ReactPlayer.js @@ -8,15 +8,7 @@ import { omit, lazy } from './utils' import Player from './Player' const Preview = lazy(() => import(/* webpackChunkName: 'reactPlayerPreview' */'./Preview')) - -const IS_BROWSER = typeof window !== 'undefined' && window.document && typeof document !== 'undefined' -const IS_GLOBAL = typeof global !== 'undefined' && global.window && global.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 || IS_GLOBAL ? Suspense : () => null - const customPlayers = [] export const createReactPlayer = (players, fallback) => { @@ -171,6 +163,12 @@ export const createReactPlayer = (players, fallback) => { const { showPreview } = this.state const attributes = this.getAttributes(url) const wrapperRef = typeof Wrapper === 'string' ? this.references.wrapper : undefined + + // Many React frameworks like Next.js support Suspense on the server but there are + // others like Fresh that don't plan to support it. Users can disable Suspense + // by setting the fallback prop to false. + const UniversalSuspense = fallback === false ? ({ children }) => children : Suspense + return (