Skip to content

onPlayerReady returns a broken THEOplayer instance when wrapped in React StrictMode #754

@TenGosc007

Description

@TenGosc007

Hello, we are using THEOplayer in our project and have recently decided to enable StrictMode globally to help us catch serious issues early. After enabling it, we discovered that our player stopped working correctly. After investigation we determined that the root cause lies within the library itself. Below is a more detailed description of the problem.

When THEOplayerView is rendered inside React StrictMode, the player instance received in the onPlayerReady callback is in a broken/stale state. Properties such as player.duration permanently return -1 and never update, even after the media finishes loading. Outside of StrictMode the same code works correctly and player.duration reflects the actual media duration.

Environment

Package Version
react-native-theoplayer 10.10.0
react 19.2.0
react-native (react-native-tvos) 0.83.1
theoplayer (web) ^10.10.0

Steps to Reproduce

  1. Clone the repository and navigate to the example directory.
  2. Move all player logic out of App.tsx into a separate component (e.g. Player.tsx) — which is exactly what the example app already does after this change.
  3. Wrap the component with <StrictMode> in App.tsx:

App.tsx

import React, { StrictMode } from 'react';
import Player from './Player';

const App = () => {
  return (
    <StrictMode>
      <Player />
    </StrictMode>
  );
};

export default App;

Player.tsx (relevant excerpt)

const onPlayerReady = useCallback((player: THEOplayer) => {
  setPlayer(player);
  player.autoplay = true;
  player.source = SOURCES[0].source;
  // ...
}, []);

// Later, player.duration === -1 and never changes
  1. Run the app on iOS or Android.
  2. Observe that player.duration is always -1 and no player events (e.g. LOADED_METADATA, LOADED_DATA) ever fire through the stored player reference.

player.duration is -1 indefinitely. Player event listeners attached in onPlayerReady do not receive events. The player appears to be in an uninitialized or already-destroyed state.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions