fix: increase OCR timeout and configure Next.js dev origins

- Increased tesseract.js worker creation timeout from 8s → 20s (accounts for lazy loading and language model download on first run)
- Added allowedDevOrigins to next.config.mjs to permit localhost and .local hostnames
- Resolves OCR timeout on slow connections and first-time initialization
This commit is contained in:
2026-04-17 11:45:36 +03:00
parent c5452c926a
commit 1ea7a48912
2 changed files with 6 additions and 1 deletions

View File

@@ -165,7 +165,7 @@ export default function Scanner({ onScanSuccess, onOCRMatch, paused }: ScannerPr
// Lazy-load tesseract.js only when OCR is actually needed // Lazy-load tesseract.js only when OCR is actually needed
const { createWorker } = await import('tesseract.js'); const { createWorker } = await import('tesseract.js');
const workerPromise = createWorker('eng'); const workerPromise = createWorker('eng');
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error("OCR Engine timeout")), 8000)); const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error("OCR Engine timeout")), 20000));
const worker = await Promise.race([workerPromise, timeoutPromise]) as any; const worker = await Promise.race([workerPromise, timeoutPromise]) as any;
const dataUrl = canvas.toDataURL('image/jpeg', 0.85); const dataUrl = canvas.toDataURL('image/jpeg', 0.85);

View File

@@ -10,6 +10,11 @@ const withPWA = withPWAInit({
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
output: "standalone", output: "standalone",
allowedDevOrigins: [
"localhost",
"127.0.0.1",
"*.local",
],
}; };
export default withPWA(nextConfig); export default withPWA(nextConfig);