question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: lazy players

See original GitHub issue

Motivation: On my page I don’t know what player will be used in each particular case and many of the players will never be used, so I would like to lazily load only one player in each particular case.

Something like this:

import React, { Suspense, lazy } from 'react'
import { whichPlayerCanPlay } from 'react-player'

const players = {
  youtube: () => import('react-player/lib/players/YouTube'),
  vimeo: () => import('react-player/lib/players/Vimeo'),
  file: () => import('react-player/lib/players/FilePlayer')
}

const MyPlayer = (props) => {
  const { url } = props

  const playerName = whichPlayerCanPlay(url, { players: ['youtube', 'vimeo', 'file'] })

  if (!playerName) {
    return null
  }

  const LazyPlayer = lazy(players[playerName]);

  return (
    <Suspense fallback={<div>Loading...</div>}>
      <LazyPlayer {...props} />
    </Suspense>
  )
}

The problem here is that the canPlay logic is inside of each individual player file and to know whether a player is capable of playing the url I need to download it. Could the canPlay logic be extracted from each individual player to a separate file?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
cookpetecommented, Apr 28, 2020

This should be fixed in v2.0.1

6reactions
cookpetecommented, Nov 6, 2019

Hey @trurl-master, yeah this has been on my radar for a long time. It would reduce the bundle size massively and essentially render the single player imports redundant. I can look at implementing this, but don’t have an exact timeline.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request: lazy players · Issue #738 · cookpete/react ...
The problem here is that the canPlay logic is inside of each individual player file and to know whether a player is capable...
Read more >
Feature Requests - WP Fusion
Feature Requests Got an idea for a new feature or integration? We'd love to hear it! You can find our roadmap here.
Read more >
Why Your Product Team Isn't Working on Your Feature Request
There is, usually, a feature request process — a process by which you ... Lazy requests will bias the Product team against your...
Read more >
We Created A Feature Request Board for World of Warcraft
This allows players a dedicated space to help collect and vote on feature requests for Retail and Classic versions of World of Warcraft, ......
Read more >
Feature Request: Rebinding all keybinds, page 3 - GOG.com
Let's hope they didn't turn into Bethesda, waiting for their players to fix what they're too lazy or incompetent to do themselves.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found