Part 15 · Best practices

Lifecycle, SSR, accessibility and user intent

Learn to: connect player lifetime with React cleanup and accessible controls.

Prerequisites: 11-clappr, 14-case-live

Browser integration lifecycle

The server renders a shell; the browser owns playback initialization. Cleanup ends the old instance’s subscriptions and media work.
The server renders a shell; the browser owns playback initialization. Cleanup ends the old instance’s subscriptions and media work. [S23] [S34]

On a narrow screen, swipe the diagram horizontally to keep its labels readable.

Lifecycle model verified

In React, an effect can connect an external player and return its cleanup. Development Strict Mode runs an extra setup/cleanup cycle. A robust adapter is safe across that cycle, source replacement and route changes. Keep browser-only initialization out of server execution.

[S34]

Example: bridge ownership synthesis

// Illustrative: mountHls is the adapter from topic 09.
useEffect(() => {
  const video = videoRef.current;
  if (!video) return;
  return mountHls(video, src, reportFailure);
}, [src, reportFailure]);
// Keep reportFailure stable. Do not add a second playback owner.
[S34] [S23]

Playback and accessibility synthesis

Autoplay can be blocked; handle a rejected play request and show a usable play control. Provide captions/transcripts and other alternatives appropriate to the content. Verify labels, visible keyboard focus, menus, fullscreen and screen-reader behavior. An attractive custom UI still needs an accessible interaction model.

[S04] [S40]

Trade-off and improvement synthesis

Begin with native controls or a documented player UI; custom controls buy design freedom but increase maintenance. Test repeated mount/unmount, source changes, keyboard-only playback, caption toggles, zoom and reduced-motion behavior. Preserve a stable aspect ratio during loading.

[S03] [S34] [S40]
Keep this: A correct player survives remounts and remains operable without a mouse.
Check yourself: What does Strict Mode’s double setup reveal?

An adapter that creates extra engines or leaves listeners alive after cleanup. It is a prompt to fix lifetime ownership, not to disable the check.

Sources & further reading

  1. [S03] The HTML video element

    MDN · official documentation · accessed 2026-10-10

    Supports: Native controls, tracks, media events, preload, playsinline and source support.

    Read this page to inspect the API and assumptions behind the cited explanation.

  2. [S04] Autoplay guide

    MDN · official documentation · accessed 2026-10-10

    Supports: Autoplay policies and handling rejected play requests.

    Read this page to inspect the API and assumptions behind the cited explanation.

  3. [S23] Hls class API

    HLS.js maintainers · official documentation · accessed 2026-10-10 · current docs

    Supports: One media element per Hls instance, destroy, level caps, buffer and bandwidth introspection.

    Read this page to inspect the API and assumptions behind the cited explanation.

  4. [S34] React useEffect

    React team · official documentation · accessed 2026-10-10

    Supports: Effect setup/cleanup and Strict Mode extra development setup/cleanup cycle.

    Read this page to inspect the API and assumptions behind the cited explanation.

  5. [S40] Making media accessible

    W3C WAI · official documentation · accessed 2026-10-10

    Supports: Captions, descriptions, transcripts and accessible player planning.

    Read this page to inspect the API and assumptions behind the cited explanation.