Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: enable Suspense by default #1775

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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