Lazy-load mediabunny on web (#11094)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-07-08 16:21:16 +03:00
committed by GitHub
parent ea3d6827c7
commit b41624edea
3 changed files with 39 additions and 12 deletions
+20
View File
@@ -0,0 +1,20 @@
type MediaBunnyModule = typeof import('mediabunny')
let promise: Promise<MediaBunnyModule> | undefined
/**
* Lazily loads mediabunny into its own webpack chunk and caches the resulting
* promise so the module is fetched at most once. If the import fails (e.g. a
* transient chunk-load error), the cached promise is reset so a later call can
* retry the load.
*/
export function loadMediaBunny(): Promise<MediaBunnyModule> {
promise ??= import(/* webpackChunkName: "mediabunny" */ 'mediabunny').catch(
e => {
// reset so a later attempt can retry after a transient chunk-load failure
promise = undefined
throw e
},
)
return promise
}