فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
perf(A07): lazy-load offline Excel only when needed
* perf(A07): defer bundled Excel library until a user explicitly requests Excel * test(A07): verify Excel is packaged locally but not imported during startup * fix(A07): await template downloads before notifying users of failures
davoodmehraban89 committed
Oct 16, 2026 at 16:35 UTC
44dca69b4b9db11803d9dc465bee4e692334b5bd
3 files changed
+33
-8
src/controllers/ExcelController.js
+18
-1
@@ -2,7 +2,18 @@
2
// ExcelController — خروجی و ورودی Excel
3
// ============================================================
4
5
-import * as XLSX from 'xlsx';
5
+// Excel and Persian text editing are not needed on the login screen.
6
+// Load the locally bundled, pinned library only when an Excel action starts.
7
+let XLSX = null;
8
+let xlsxPending = null;
9
+async function loadSheetJS() {
10
+ if (XLSX) return XLSX;
11
+ if (!xlsxPending) {
12
+ xlsxPending = import('xlsx').then(module => { XLSX = module; return module; })
13
+ .catch(error => { xlsxPending = null; throw error; });
14
+ }
15
+ return xlsxPending;
16
+}
17
import { StorageService } from '../core/StorageService.js';
18
import { Auth } from '../core/Auth.js';
19
import { DataScope } from '../core/DataScope.js';
@@ -16,6 +27,7 @@ class ExcelControllerImpl {
27
// ذخیره فایل + نمایش پیام + باز کردن خودکار (سازگار با Tauri)
28
// ============================================================
29
async _saveFile(wb, fileName) {
30
+ await loadSheetJS();
31
const isTauri = '__TAURI_INTERNALS__' in window;
32
33
// حالت مرورگر: دانلود معمولی
@@ -61,6 +73,7 @@ class ExcelControllerImpl {
73
// خروجی کامل (Backup Excel)
74
// ============================================================
75
async exportAll() {
76
+ await loadSheetJS();
77
const user = Auth.current();
78
if (!user) throw new Error('کاربر یافت نشد');
79
@@ -295,6 +308,7 @@ class ExcelControllerImpl {
308
// خروجی انتخابی
309
// ============================================================
310
async exportSection(section) {
311
+ await loadSheetJS();
312
const user = Auth.current();
313
if (!user) throw new Error('کاربر یافت نشد');
314
@@ -402,6 +416,7 @@ class ExcelControllerImpl {
416
// ورودی از Excel
417
// ============================================================
418
async readExcelFile(file) {
419
+ await loadSheetJS();
420
return new Promise((resolve, reject) => {
421
const reader = new FileReader();
422
reader.onload = (e) => {
@@ -558,6 +573,7 @@ class ExcelControllerImpl {
573
// دانلود قالبهای نمونه
574
// ============================================================
575
async downloadProductsTemplate() {
576
+ await loadSheetJS();
577
const data = [
578
['کد', 'نام', 'مشخصه', 'واحد', 'قیمت خرید', 'قیمت فروش', 'نقطه سفارش', 'نوع'],
579
['P001', 'هارد سرور 2.5 اینچ', 'SAS 1TB', 'عدد', 30000000, 37000000, 5, 'کالا'],
@@ -571,6 +587,7 @@ class ExcelControllerImpl {
587
}
588
589
async downloadContactsTemplate() {
590
+ await loadSheetJS();
591
const data = [
592
['نام', 'نوع', 'نقش', 'موبایل', 'تلفن', 'کد ملی/شناسه', 'کد اقتصادی', 'شماره ثبت', 'کد پستی', 'نشانی'],
593
['شرکت آرا بتن', 'حقوقی', 'مشتری', '09124376991', '', '14008507476', '14008507476', '544926', '1445956311', 'تهران'],
src/views/SettingsView.js
+12
-6
@@ -367,14 +367,20 @@ class SettingsViewImpl {
367
}
368
}
369
370
- downloadProductsTemplate() {
371
- ExcelController.downloadProductsTemplate();
372
- Toast.success('قالب کالاها دانلود شد');
370
+ async downloadProductsTemplate() {
371
+ try {
372
+ await ExcelController.downloadProductsTemplate();
373
+ } catch (error) {
374
+ Toast.error('ساخت قالب کالاها ناموفق بود: ' + error.message);
375
+ }
376
}
377
375
- downloadContactsTemplate() {
376
- ExcelController.downloadContactsTemplate();
377
- Toast.success('قالب اشخاص دانلود شد');
378
+ async downloadContactsTemplate() {
379
+ try {
380
+ await ExcelController.downloadContactsTemplate();
381
+ } catch (error) {
382
+ Toast.error('ساخت قالب اشخاص ناموفق بود: ' + error.message);
383
+ }
384
}
385
386
// ============================================================
tests/a07-offline-bundled-assets.test.mjs
+3
-1
@@ -13,7 +13,9 @@ test('A07: the app shell cannot block startup on a remote CDN', () => {
13
assert.doesNotMatch(html, /<link[^>]*href=["']https?:\/\//i);
14
assert.match(entry, /@fontsource\/vazirmatn\/400\.css/);
15
assert.match(entry, /@fontsource\/vazirmatn\/700\.css/);
16
- assert.match(excel, /import \* as XLSX from 'xlsx'/);
16
+ assert.match(excel, /import\('xlsx'\)/);
17
+ assert.doesNotMatch(excel, /import \* as XLSX from 'xlsx'/);
18
+ assert.match(excel, /async function loadSheetJS\(\)/);
19
});
20
21
test('A07: bundled SheetJS can read and write Persian spreadsheets with integer currency', () => {