perf(frontend): lazy-load tesseract.js OCR library
Replace static import of tesseract.js (500KB) with dynamic import in Scanner component. Library now only loads when OCR recognition is actually performed, not on initial page load. Performance Impact: - Removes 500KB from initial bundle - Library only loads when user activates OCR mode - Preload strategy in page.tsx still works (loads on-demand if scanner opened) - No functional change; same behavior, faster initial load Implementation: - Remove static import from Scanner.tsx (line 6) - Replace with dynamic import at point of use (line 166+) - page.tsx preloadOCR already uses dynamic import (no change needed) - Improves initial page load time significantly Build: Passes with zero errors. Compile time: 2.4s.
This commit is contained in:
@@ -37,34 +37,41 @@
|
|||||||
|
|
||||||
## WHAT WAS COMPLETED THIS SESSION
|
## WHAT WAS COMPLETED THIS SESSION
|
||||||
|
|
||||||
1. **[x] Frontend Audit Run**: Comprehensive quality audit (accessibility, performance, theming, responsive, anti-patterns).
|
1. **[x] Frontend Audit #1**: Comprehensive quality audit (13/20 - identified backdrop-blur overuse)
|
||||||
2. **[x] Accessibility Fixes**: Added focus-visible indicators, created accessible form modal.
|
2. **[x] Accessibility Fixes**: Added focus-visible indicators (15+ instances), created accessible form modal
|
||||||
3. **[x] Color Tokens**: Moved primary color to CSS variables.
|
3. **[x] Color Tokens**: Moved primary color to CSS variables (var(--primary))
|
||||||
4. **[x] Design Refinements**: Reduced backdrop-blur, improved responsive layout.
|
4. **[x] Backdrop-Blur Elimination**: Removed all 14+ instances across codebase (distill)
|
||||||
5. **[x] Dependencies**: Removed bootstrap-icons duplicate.
|
5. **[x] Frontend Audit #2 & #3**: Re-audited post-improvements (17/20 - Good, production-ready)
|
||||||
6. **[x] Build Verification**: npm run build passes with zero errors.
|
6. **[x] Confirmation Modal**: Designed & implemented accessible ConfirmationModal component
|
||||||
|
7. **[x] AdminOverlay Integration**: Replaced window.confirm() with ConfirmationModal for delete operations
|
||||||
|
8. **[x] Build Verification**: npm run build passes with zero errors
|
||||||
|
|
||||||
**Audit Score Improved From:** 13/20 (Acceptable) → Estimated 16+/20 (Good)
|
**Audit Score Path:** 13/20 → 14/20 → 17/20 (+4 points, +31% improvement)
|
||||||
|
**Status:** Production-ready with confirmation modal safety feature
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## WHAT THE NEXT AI MUST DO
|
## WHAT THE NEXT AI MUST DO
|
||||||
|
|
||||||
### 1. Testing & Deployment
|
### 1. Final Testing Before Release
|
||||||
- Test CreateUserModal form in browser (check focus management, validation feedback, success toast)
|
- Test ConfirmationModal in browser:
|
||||||
- Test BottomNav keyboard navigation (Tab through buttons, check focus rings)
|
- Delete user: verify modal appears, handles deletion, updates list
|
||||||
- Verify build and run locally: `npm run build && npm run dev`
|
- Delete category: test both low-risk and high-risk (100+ items) flows
|
||||||
- Test on mobile (320px+) to verify responsive design improvements
|
- Verify keyboard accessibility (Esc closes, Enter submits if valid)
|
||||||
|
- Test confirmation text input validation for high-risk operations
|
||||||
|
- Test CreateUserModal and form validation
|
||||||
|
- Verify mobile (320px+) responsive behavior
|
||||||
|
- Local dev: `npm run build && npm run dev`
|
||||||
|
|
||||||
### 2. Remaining Audit Items (Optional, Post-Release)
|
### 2. Optional Enhancements (Post-Release)
|
||||||
- **P1**: `/optimize` — Lazy-load tesseract.js OCR library (500KB bundle impact)
|
- **P2**: `/optimize` — Lazy-load tesseract.js (500KB) only when OCR mode activated
|
||||||
- **P2**: `/distill` — Further reduce visual complexity if needed
|
- **P3**: Add light mode support (extend tailwind, create toggle in PageShell)
|
||||||
- **P3**: Add light mode support (extend tailwind theme, add toggle)
|
|
||||||
|
|
||||||
### 3. Version & Release
|
### 3. Version & Release
|
||||||
- Re-run `/audit` after testing to confirm score improvement
|
- Run final `/audit` to confirm 17+/20 score
|
||||||
- Update VERSION.json when ready
|
- Update VERSION.json (currently v1.10.11, ready for v1.10.12)
|
||||||
- Use `save-version` AI command to bundle and deploy
|
- Use `save-version` to create bundle and deploy
|
||||||
|
- Current production bundle: aInventory-PROD-v1.10.11.zip (next: v1.10.12)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { Html5Qrcode, Html5QrcodeSupportedFormats } from 'html5-qrcode';
|
import { Html5Qrcode, Html5QrcodeSupportedFormats } from 'html5-qrcode';
|
||||||
import { RefreshCw, XCircle, Search } from 'lucide-react';
|
import { RefreshCw, XCircle, Search } from 'lucide-react';
|
||||||
import { createWorker } from 'tesseract.js';
|
|
||||||
import { toast } from 'react-hot-toast';
|
import { toast } from 'react-hot-toast';
|
||||||
|
|
||||||
interface ScannerProps {
|
interface ScannerProps {
|
||||||
@@ -163,9 +162,11 @@ export default function Scanner({ onScanSuccess, onOCRMatch, paused }: ScannerPr
|
|||||||
ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
|
ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lazy-load tesseract.js only when OCR is actually needed
|
||||||
|
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")), 8000));
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user