Skip to content

Commit

Permalink
feat!: enable Suspense by default (#1775)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: enable Suspense by default, remove environment checks
  • Loading branch information
luwes authored Apr 19, 2024
1 parent 795b196 commit 37c5683
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 (
<Wrapper ref={wrapperRef} style={{ ...style, width, height }} {...attributes}>
<UniversalSuspense fallback={fallback}>
Expand Down

0 comments on commit 37c5683

Please sign in to comment.