Skip to content

fix(mux-input): mount the Mux player only after clicking the poster - #2074

Merged
pedrobonamin merged 2 commits into
mainfrom
cursor/sieve-2068-c377
Oct 26, 2026
Merged

pedrobonamin merged 2 commits into
mainfrom
cursor/sieve-2068-c377

Conversation

@pedrobonamin

Copy link
Copy Markdown
Contributor

Summary

Every visible mux.video input rendered a full <MuxPlayer> as soon as the field mounted. While the player's media-chrome controls upgrade, they force several full-document layouts, and the issue reports this freezes Safari for seconds on forms with multiple video fields.

With this change, the form input shows the poster as a play button. <MuxPlayer> mounts (with autoPlay) only after a click.

  • VideoPlayer gets an opt-in deferPlayer prop. Only the input's Player sets it. The asset browser (VideoInBrowser, which already defers with its own play button) and the video details dialog behave as before.
  • These stay available before the player mounts: the actions menu overlay (upload, browse, thumbnail, captions…), the static-rendition notice, and the thumbnail/captions/mezzanine dialogs. The thumbnail dialog starts at time 0 when no player is mounted, which is the dialog's existing default.
  • PlayButton moves out of VideoInBrowser into its own module so both places share it. In the input, the play icon is always visible.

Investigation

  • Mechanism (confirmed in the installed media-chrome 4.19.2): media-chrome-button's attributeChangedCallback calls MediaTooltip.updateXOffset on every observed attribute change. That function runs checkVisibility(), getComputedStyle().getPropertyValue() and getBoundingClientRect() on both the tooltip and its container, which matches the reporter's Safari sample. The root cause is in media-chrome; this PR only stops the plugin from triggering it for videos the editor never plays.
  • Not reproduced: the Safari freeze itself. No Safari/WebKit is available in this Linux environment, so the timing could not be measured.

Testing

  • New src/components/VideoPlayer.test.tsx (jsdom, with @mux/mux-player-react/lazy mocked):
    • By default, the player mounts eagerly and has no play button.
    • With deferPlayer, no player is in the DOM, the poster <img> uses the Mux thumbnail URL, and overlay children render once. After a click, the player mounts with autoPlay.
    • When the deferral is temporarily forced off, the test fails as expected.
  • pnpm lint and the sanity-plugin-mux-input build and tests pass. pnpm knip fails only on the root lefthook devDependency, which also fails on a clean tree and is unrelated to this change.
  • Manual test in the test studio (Chrome), on a muxTrailer document:
    • Before clicking: the poster and play icon show, and document.querySelectorAll('mux-player').length is 0.
    • Opening the actions menu does not mount the player.
    • Clicking the poster mounts the player (count 1), which autoplays.

Poster before click
Player after click
mux-deferred-player.mp4

Lockfile

The test adds @testing-library/react, @types/react-dom and jsdom as dev dependencies, on the same catalog versions other plugins already lock. Only the three importer entries were added to pnpm-lock.yaml, and pnpm install --frozen-lockfile passes. A plain pnpm install would also re-resolve the next-tagged Studio overrides (sanity 6.17.0-next.112 → 6.18.0-next.21), so that bump is deliberately not included.

Fixes #2068

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

@changeset-bot

changeset-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9289eb6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
sanity-plugin-mux-input Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
plugins-studio Ready Ready Preview Oct 26, 2026 6:47am UTC
1 Skipped Deployment
Project Deployment Actions Updated
plugins-e2e-test-studio Ignored Ignored Oct 26, 2026 6:47am UTC

Request Review

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

✅ E2E Tests

🟢 46 passed • view full report • view run

Studio: https://plugins-e2e-test-studio-ae7qwgn0i.sanity.dev

Datasets: pr-2074-chromium-40281790840, pr-2074-firefox-40281790840

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 38.44% 7742 / 20137
🔵 Statements 38.41% 8329 / 21684
🔵 Functions 34.11% 2115 / 6200
🔵 Branches 30.62% 4489 / 14660
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
plugins/sanity-plugin-mux-input/src/components/PlayButton.tsx 100% 100% 100% 100%
plugins/sanity-plugin-mux-input/src/components/Player.tsx 2.38% 0% 0% 2.43% 19-127
plugins/sanity-plugin-mux-input/src/components/VideoInBrowser.tsx 0% 0% 0% 0% 31-128
plugins/sanity-plugin-mux-input/src/components/VideoPlayer.tsx 68.96% 58.82% 71.42% 72.22% 68, 72-73, 79, 83-84, 94, 98, 101-105, 131-133, 137, 142, 151-154
Generated in workflow #11356 for commit 9289eb6 by the Vitest Coverage Report Action

@pedrobonamin
pedrobonamin requested a balanced review from Copilot October 2, 2026 13:05
@pedrobonamin
pedrobonamin marked this pull request as ready for review October 2, 2026 13:06
@pedrobonamin
pedrobonamin requested review from a team as code owners October 2, 2026 13:06
@pedrobonamin
pedrobonamin requested review from bjoerge and spuppo-mux and removed request for a team and bjoerge October 2, 2026 13:06
@pedrobonamin
pedrobonamin requested a review from a team October 2, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Deferred state persists across asset replacement, causing replacement videos to mount and autoplay without a new click.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Defers Mux player mounting in video inputs until the poster is activated, reducing Safari layout stalls while preserving eager playback elsewhere.

Changes:

  • Adds opt-in deferred player rendering with an accessible poster button.
  • Shares the existing play-button component across views.
  • Adds Vitest coverage and required test dependencies.
File Description
.changeset/​mux-input-defer-player.md Records the Safari performance fix.
pnpm-lock.yaml Locks new test dependencies.
plugins/​sanity-plugin-mux-input/​package.json Adds testing dependencies.
src/​components/​Player.tsx Enables deferred playback in inputs.
src/​components/​PlayButton.tsx Extracts the shared play button.
src/​components/​VideoInBrowser.tsx Uses the shared play button.
src/​components/​VideoPlayer.tsx Implements poster-first deferred mounting.
src/​components/​VideoPlayer.test.tsx Tests eager and deferred behavior.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation addresses the reported performance issue while preserving existing behavior in other player contexts and adding focused regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

@spuppo-mux

Copy link
Copy Markdown
Collaborator

Changes look great; will test it out! Haven't set up my workspace since the repo migration so it may take me a minute. Just in case, did you test this with audio only assets and/or signed assets?

@pedrobonamin

Copy link
Copy Markdown
Contributor Author

Changes look great; will test it out! Haven't set up my workspace since the repo migration so it may take me a minute. Just in case, did you test this with audio only assets and/or signed assets?

Thank you @spuppo-mux let us know if you have any difficulties setting up the new workspace, in my experience it should be much simpler now.

No, haven't tested with audio only assets or signed assets, good catch, will test it next week.

@pedrobonamin
pedrobonamin requested review from a team and skogsmaskin and removed request for a team October 23, 2026 10:26
@cursor
cursor Bot requested a review from a team as a code owner October 23, 2026 10:30
@spuppo-mux

Copy link
Copy Markdown
Collaborator

Hi, btw I could test this with no issues. Audio-only, signed and drm cases seemed to work well to me!

spuppo-mux
spuppo-mux previously approved these changes Oct 23, 2026
cursoragent and others added 2 commits October 26, 2026 06:44
Every visible mux.video input mounted a full <mux-player> eagerly. Its
media-chrome buttons force several full-document layouts while upgrading,
which freezes Safari for seconds on forms with multiple video fields.

The input now shows the poster with a play button and mounts the player
(with autoplay) on click. The asset browser and details dialog are
unchanged.

Fixes #2068

Co-authored-by: Pedro Bonamin <pedrobonamin@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@pedrobonamin

Copy link
Copy Markdown
Contributor Author

Thank you @spuppo-mux had to rebase due to some conflicts, would you mind approving again?

@pedrobonamin
pedrobonamin enabled auto-merge (squash) October 26, 2026 07:19
@pedrobonamin
pedrobonamin disabled auto-merge October 26, 2026 14:31
@pedrobonamin
pedrobonamin merged commit 1494069 into main Oct 26, 2026
25 checks passed
@pedrobonamin
pedrobonamin deleted the cursor/sieve-2068-c377 branch October 26, 2026 14:31
@squiggler-app squiggler-app Bot mentioned this pull request Oct 26, 2026
pedrobonamin pushed a commit that referenced this pull request Oct 26, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## sanity-plugin-mux-input@5.2.1

### Patch Changes

- [#2074](#2074)
[`1494069`](1494069)
Thanks [@pedrobonamin](https://github.com/pedrobonamin)! - Show the
video poster with a play button in the input and only mount the Mux
player when the editor clicks it, so opening forms with several video
fields no longer freezes Safari

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Version and changelog-only release; the underlying change is a Studio
UI performance fix with no API or security surface in this PR.
> 
> **Overview**
> **Release-only PR:** bumps `sanity-plugin-mux-input` from **5.2.0** to
**5.2.1**, adds the **5.2.1** changelog entry, and removes the consumed
changeset (`.changeset/mux-input-defer-player.md`). No application
source changes in this diff.
> 
> The published patch documents
[#2074](#2074): the Studio
video input shows a **poster + play control** and **defers mounting
`MuxPlayer`** until the editor clicks, avoiding Safari freezes when
forms load many Mux fields.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
a9d8bee. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: squiggler-app[bot] <265501495+squiggler-app[bot]@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview – plugins-studio — 9289eb6b Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[sanity-plugin-mux-input] mounting <mux-player> for every visible video field freezes Safari for seconds

4 participants