-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mux Uploader Server Component #913
base: main
Are you sure you want to change the base?
Conversation
## How it works ### Defaults If no `endpoint` is specified, will use `@mux/mux-node` to create a direct upload with the following configuration: ```ts { cors_origin: '*', new_asset_settings: { playback_policy: ['public'], encoding_tier: 'baseline', } ``` ### How to configure Accepts all the same params as Mux Uploader, as well as ```ts interface MuxUploaderServerProps extends MuxUploaderProps { clientOptions?: ClientOptions; uploadCreateParams?: Partial<Mux.Video.Uploads.UploadCreateParams>; uploadRequestOptions?: Partial<Mux.RequestOptions>; } ``` `uploadCreateParams` will be deep-merged with the default options described above ## TODO items: - [ ] get some feedback - [ ] answer some questions 👇 - [ ] documentation ## Outstanding questions: for those of you who know esbuild and bundlers better than I do: - [ ] why is @mux/mux-uploader-react/rsc giving me a red squiggle in the nextjs example? why can't typescript find it? - [ ] is it correct to external:server-only even though it's not a peer dependency?
@decepulis is attempting to deploy a commit to the Mux Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
What could it look like for this component (or set of them) to be able to return things like an asset ID / playback ID? |
Running into a huge blocker with this. Consider the following: import MuxUploader from '@mux/mux-uploader-react/rsc';
function MuxUploaderPage() {
return (
<MuxUploader onSuccess={console.log} />
);
}
export default MuxUploaderPage; However, you can't pass client functionality (in our example, Gotta think of another interface if we want this to happen... |
@mmcc btw just to answer this. Server Actions would make this really slick. Under the hood, we could implement something like this: // packages/mux-uploader-react
import 'server-only'
import MuxUploaderClient from './index'
const MuxUploaderServer = (props) => {
const upload = await mux.video.uploads.create(...);
return (
<MuxUploaderClient
endpoint={upload.url}
onSuccess={
"use server"
const assetId = await getAssetIdForUpload(upload.id)
props.onAssetId(assetId)
}
/>
)
} And it gets more exciting. I've actually got this implemented in another branch. Just gotta think through... my previous comment... |
Let's take another shot at #712...
How to use it
Defaults
If no
endpoint
is specified, will use@mux/mux-node
to create a direct upload with the following configuration:How to configure
Accepts all the same params as Mux Uploader, as well as
uploadCreateParams
will be deep-merged with the default options described aboveHow it gets bundled
lemme point out some interesting flags, here:
--platform=node
: in order to avoid bundling dependencies likecrypto
, esbuild requires this of us. Luckily, Server Components run on the server, so, this is correct--external:server-only
: the contents of this package is literally justthrow new Error('This is a server component and can't be imported in a client component')
(paraphrased). If we were to bundle it, our bundle would immediately throw an error. I suspect that, in practice, server-component-compliant bundlers will know to ignore this import. Even so, shouldserver-only
be marked as a peer dependency? 🤔--external:./index
: In order for server component bundlers to leave the server stuff on the server and the client stuff on the client, we have to ship the server bundle and the client bundle separately. By markingindex
as external, we're telling esbuild "don't include the client bundle in the server bundle". Instead, consumer bundlers will see this indist/rsc.mjs
and resolvedist/index.mjs
(ordist/rsc.cjs.js
anddist/index.cjs.js
respectively).TODO items:
--external:server-only
and--external:./index
? This seems to work in our test Next app, so that's a good sign...@mux/mux-uploader-react/rsc
giving me a red squiggle in the nextjs example? why can't typescript find it? or is that just something in my environment?Other passing thoughts
I don't re-export the types, so right now if you want those, you'll have to
import type { ... } from '@mux/mux-uploader-react'
. TypeScript should pick up on that; I'm not worried