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
+36
View File
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
-5
View File
@@ -1,11 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
webpack: (config) => {
// Requis pour onnxruntime-web (WASM) utilisé par @imgly/background-removal
config.experiments = { ...config.experiments, asyncWebAssembly: true }
return config
},
};
export default nextConfig;
+42
View File
@@ -0,0 +1,42 @@
'use client'
import { Component, type ReactNode } from 'react'
interface Props {
children: ReactNode
fallback?: (error: Error, reset: () => void) => ReactNode
}
interface State {
error: Error | null
}
export class ErrorBoundary extends Component<Props, State> {
state: State = { error: null }
static getDerivedStateFromError(error: Error): State {
return { error }
}
reset = () => this.setState({ error: null })
render() {
if (this.state.error) {
if (this.props.fallback) return this.props.fallback(this.state.error, this.reset)
return (
<div className="p-6">
<div className="bg-red-900/30 border border-red-700 rounded-xl p-6 text-center space-y-3">
<p className="text-red-300 font-semibold">Une erreur est survenue</p>
<p className="text-red-400 text-sm font-mono">{this.state.error.message}</p>
<button
onClick={this.reset}
className="px-4 py-2 bg-slate-700 hover:bg-slate-600 text-white rounded-lg text-sm"
>
Réessayer
</button>
</div>
</div>
)
}
return this.props.children
}
}
+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])
})
}
/**