perf: lazy-load xlsx/recharts, split estimate tabs, memoize nav
- xlsx dynamically imported via cached singleton in excel.ts and skillMatrixParser.ts (removes ~100 kB from 4 routes) - recharts extracted into lazy-loaded SkillDistributionChart and PeakTimesChart components (removes ~60 kB from 3 routes) - EstimateWorkspaceClient: 7 tab components + 2 editors loaded via next/dynamic (reduces /estimates/[id] from 323 kB to 138 kB) - ImportModal lazy-loaded in ResourcesClient (deferred until open) - NavItem memoized with React.memo, top 5 routes get prefetch=true - Raw <img> replaced with next/image in ProjectsClient, CoverArtSection - tRPC QueryClient: refetchOnWindowFocus/Reconnect disabled globally Heaviest routes reduced 39-66% First Load JS: /analytics/skills: 383→132 kB (-66%) /estimates/[id]: 323→138 kB (-57%) /resources/[id]: 458→210 kB (-54%) /estimates: 310→170 kB (-45%) /resources: 363→222 kB (-39%) Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
+24
-29
@@ -1,37 +1,32 @@
|
||||
import * as XLSX from "xlsx";
|
||||
let _xlsx: typeof import("xlsx") | null = null;
|
||||
|
||||
async function getXLSX() {
|
||||
if (!_xlsx) {
|
||||
_xlsx = await import("xlsx");
|
||||
}
|
||||
return _xlsx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an Excel (.xlsx, .xls) or CSV file to an array of row objects.
|
||||
* Keys come from the first row (headers).
|
||||
*/
|
||||
export function parseSpreadsheet(file: File): Promise<Record<string, string>[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
const data = new Uint8Array(e.target!.result as ArrayBuffer);
|
||||
const workbook = XLSX.read(data, { type: "array" });
|
||||
const sheetName = workbook.SheetNames[0];
|
||||
if (!sheetName) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
const sheet = workbook.Sheets[sheetName];
|
||||
if (!sheet) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
const rows = XLSX.utils.sheet_to_json<Record<string, string>>(sheet, {
|
||||
raw: false,
|
||||
defval: "",
|
||||
});
|
||||
resolve(rows);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
reader.onerror = () => reject(reader.error);
|
||||
reader.readAsArrayBuffer(file);
|
||||
export async function parseSpreadsheet(file: File): Promise<Record<string, string>[]> {
|
||||
const XLSX = await getXLSX();
|
||||
const buffer = await file.arrayBuffer();
|
||||
const data = new Uint8Array(buffer);
|
||||
const workbook = XLSX.read(data, { type: "array" });
|
||||
const sheetName = workbook.SheetNames[0];
|
||||
if (!sheetName) {
|
||||
return [];
|
||||
}
|
||||
const sheet = workbook.Sheets[sheetName];
|
||||
if (!sheet) {
|
||||
return [];
|
||||
}
|
||||
return XLSX.utils.sheet_to_json<Record<string, string>>(sheet, {
|
||||
raw: false,
|
||||
defval: "",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import * as XLSX from "xlsx";
|
||||
import type { SkillEntry } from "@planarchy/shared";
|
||||
|
||||
let _xlsx: typeof import("xlsx") | null = null;
|
||||
|
||||
async function getXLSX() {
|
||||
if (!_xlsx) {
|
||||
_xlsx = await import("xlsx");
|
||||
}
|
||||
return _xlsx;
|
||||
}
|
||||
|
||||
export interface ParsedEmployeeInfo {
|
||||
displayName?: string;
|
||||
areaOfExpertise?: string;
|
||||
@@ -82,7 +90,8 @@ function parseSkillSheet(rows: Record<string, string>[], mainSkillSet: Set<strin
|
||||
* Parse a skill matrix workbook (xlsx ArrayBuffer) into structured data.
|
||||
* Returns ParsedSkillMatrix with employeeInfo and merged skills array.
|
||||
*/
|
||||
export function parseSkillMatrixWorkbook(data: ArrayBuffer): ParsedSkillMatrix {
|
||||
export async function parseSkillMatrixWorkbook(data: ArrayBuffer): Promise<ParsedSkillMatrix> {
|
||||
const XLSX = await getXLSX();
|
||||
const workbook = XLSX.read(new Uint8Array(data), { type: "array" });
|
||||
|
||||
const employeeSheet = workbook.Sheets["Employee Information"];
|
||||
|
||||
@@ -27,7 +27,9 @@ export function TRPCProvider({ children }: { children: React.ReactNode }) {
|
||||
new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 60 * 1000, // 60 seconds — reduces refetches on navigation
|
||||
staleTime: 60_000, // 60 seconds — reduces refetches on navigation
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
retry: 1,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user