Skip to content

fix(mux-input): keep the uploaded file's name as the video's filename - #2266

Open
eeeurico wants to merge 1 commit into
sanity-io:mainfrom
eeeurico:fix/mux-keep-upload-filename
Open

eeeurico wants to merge 1 commit into
sanity-io:mainfrom
eeeurico:fix/mux-keep-upload-filename

Conversation

@eeeurico

@eeeurico eeeurico commented Oct 27, 2026 •

Copy link
Copy Markdown

What happens today

When a video is uploaded as a file, the mux.videoAsset document is written without a filename. The Studio then lists the video under assetId.slice(0, 12) (for example iKmsiHRjURhL) in the video browser, the details dialog and the input preview. The name the editor chose for the file is not stored anywhere: it is not on the Sanity document, and no title is sent to Mux either.

URL uploads already pass a filename to the proxy, so this only affects file uploads. I checked 2.x and 3.x as well as 5.2.1, and none of them stored the file name, so this is long-standing rather than a regression.

On our dataset, 492 of 494 videos had no name after a couple of years of uploads, and the only way to find a video in the browser was by its ID.

The change

  • uploadFile passes file.name to updateAssetDocumentFromUpload.
  • uploadedAssetTransaction takes the optional filename and adds setIfMissing({filename}) to the patch it already makes.

The change uses setIfMissing rather than set because uploadedAssetTransaction patches instead of replacing so that fields written while the upload is processing are kept. A name typed into the details dialog during that time still wins.

Tests

I added a case to upload.test.ts that checks the serialized transaction carries setIfMissing: {filename}. The existing case (no filename) is unchanged. I've checked the expected mutation shape against @sanity/client directly, but I haven't run the monorepo's full pnpm format/lint/knip/build/test locally, so CI is the first full run.

We've been running the same fix as a pnpm patch on 5.0.10 in production: a new upload is listed as mux-filename-test.mp4 instead of its ID.

Not in this PR

  • Sending the name to Mux as meta.title. I tried adding it to the upload settings, but the asset came back without meta, so the uploads proxy doesn't seem to forward it. That makes Sync all titles in the Videos tool set filename to muxTitle || "" for every asset, which blanks names that only exist in Sanity. It might be worth guarding that the way Fill missing titles only already is.
  • An upload button in the Videos tool. Today uploads are only possible from a mux.video field.

Note

Low Risk
Narrow upload-completion patch behavior using setIfMissing; no auth or API surface changes, and existing documents without filename are unchanged.

Overview
File uploads now persist the browser file’s name on the mux.videoAsset document so Studio lists videos by that name instead of a truncated Mux asset ID.

On successful upload, uploadFile passes file.name into updateAssetDocumentFromUpload, which forwards it to uploadedAssetTransaction. That transaction still patches Mux fields with set, and when a name is provided it also applies setIfMissing({ filename }) so an editor-assigned title during upload is not overwritten. URL uploads were already setting filename via the proxy; this closes the gap for direct file picks.

A unit test asserts the serialized Sanity transaction includes setIfMissing: { filename: '…' } when a filename is passed.

Reviewed by Cursor Bugbot for commit 6767ab6. Bugbot is set up for automated code reviews on this repo. Configure here.

@eeeurico
eeeurico requested review from a team as code owners October 27, 2026 00:51
@eeeurico
eeeurico requested review from danielgroves and juice49 and removed request for a team October 27, 2026 00:51
@vercel

vercel Bot commented Oct 27, 2026

Copy link
Copy Markdown

@eeeurico is attempting to deploy a commit to the Sanity Sandbox Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6767ab6

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

A file upload created the mux.videoAsset document without a filename, so
the Studio listed every new video under a slice of its Mux asset ID. Fill
filename from the uploaded file with setIfMissing, so a name typed while
the upload was processing still wins.
@eeeurico
eeeurico force-pushed the fix/mux-keep-upload-filename branch from 5f0faa6 to 6767ab6 Compare October 27, 2026 00:53

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant