fix: revert @imgly npm import → CDN + ErrorBoundary + next.config cleanup

This commit is contained in:
2026-06-09 13:15:04 +02:00
parent a77f44b800
commit 4b9db5bebf
4 changed files with 91 additions and 11 deletions
+13 -6
View File
@@ -1,7 +1,14 @@
import { removeBackground } from '@imgly/background-removal'
const CDN_URL = 'https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/index.mjs'
// URL CDN pour les ressources (WASM + modèles ONNX) — évite de les héberger localement
const IMGLY_CDN = 'https://cdn.jsdelivr.net/npm/@imgly/background-removal@1.7.0/dist/'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let _removeBg: ((blob: Blob, opts: Record<string, unknown>) => Promise<Blob>) | null = null
async function loadLib() {
if (_removeBg) return _removeBg
const mod = await import(/* webpackIgnore: true */ CDN_URL)
_removeBg = mod.removeBackground
return _removeBg!
}
export interface ProgressEvent {
key: string
@@ -16,15 +23,15 @@ export async function removeBackgroundRaw(
blob: Blob,
onProgress?: (e: ProgressEvent) => void,
): Promise<Blob> {
return removeBackground(blob, {
publicPath: IMGLY_CDN,
const removeBg = await loadLib()
return removeBg(blob, {
output: { format: 'image/png', type: 'foreground', quality: 1 },
progress: (key: string, current: number, total: number) => {
if (onProgress && total > 0) {
onProgress({ key, percent: Math.round((current / total) * 100) })
}
},
} as Parameters<typeof removeBackground>[1])
})
}
/**