remove logging and stop rerender

This commit is contained in:
Anthony Stirling 2025-11-11 17:21:50 +00:00
parent 84c0962b4c
commit 4272edc89d
2 changed files with 27 additions and 33 deletions

View File

@ -268,27 +268,6 @@ const analyzePageContentType = (groups: TextGroup[]): boolean => {
avgWordsPerGroup > 12 ||
longTextRatio > 0.4;
// Log detailed statistics
console.group(`📊 Page Content Analysis`);
console.log('📄 Overall Statistics:');
console.log(` Total text groups: ${totalGroups}`);
console.log(` Total words: ${totalWords}`);
console.log(` Average words per group: ${avgWordsPerGroup.toFixed(2)}`);
console.log(` Multi-line groups: ${multiLineGroups}`);
console.log(` Long text groups (≥5 words or ≥30 chars): ${longTextGroups}`);
console.log(` Long text ratio: ${(longTextRatio * 100).toFixed(1)}%`);
console.log('');
console.log('🔍 Detection Criteria:');
console.log(` ✓ Multi-line groups ≥ 2 AND avg words > 8? ${multiLineGroups >= 2 && avgWordsPerGroup > 8 ? '✅ YES' : '❌ NO'} (multi-line: ${multiLineGroups}, avg: ${avgWordsPerGroup.toFixed(2)})`);
console.log(` ✓ Avg words/group > 12? ${avgWordsPerGroup > 12 ? '✅ YES' : '❌ NO'} (current: ${avgWordsPerGroup.toFixed(2)})`);
console.log(` ✓ Long text ratio > 40%? ${longTextRatio > 0.4 ? '✅ YES' : '❌ NO'} (current: ${(longTextRatio * 100).toFixed(1)}%)`);
console.log('');
console.log(`📋 Result: ${isParagraphPage ? '📝 PARAGRAPH PAGE' : '📄 SPARSE PAGE'}`);
console.log('');
console.log('📦 Individual Groups:');
console.table(groupDetails);
console.groupEnd();
return isParagraphPage;
};

View File

@ -101,6 +101,7 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
const previewRenderingRef = useRef<Set<number>>(new Set());
const pagePreviewsRef = useRef<Map<number, string>>(pagePreviews);
const previewScaleRef = useRef<Map<number, number>>(new Map());
const cachedJobIdRef = useRef<string | null>(null);
// Keep ref in sync with state for access in async callbacks
useEffect(() => {
@ -119,6 +120,7 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
pagePreviewsRef.current = pagePreviews;
}, [pagePreviews]);
useEffect(() => {
return () => {
if (pdfDocumentRef.current) {
@ -185,6 +187,24 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
setHasVectorPreview(false);
}, []);
const clearCachedJob = useCallback((jobId: string | null) => {
if (!jobId) {
return;
}
console.log(`[PdfJsonEditor] Cleaning up cached document for jobId: ${jobId}`);
apiClient.post(`/api/v1/convert/pdf/json/clear-cache/${jobId}`).catch((error) => {
console.warn('[PdfJsonEditor] Failed to clear cache:', error);
});
}, []);
useEffect(() => {
const previousJobId = cachedJobIdRef.current;
if (previousJobId && previousJobId !== cachedJobId) {
clearCachedJob(previousJobId);
}
cachedJobIdRef.current = cachedJobId;
}, [cachedJobId, clearCachedJob]);
const initializePdfPreview = useCallback(
async (file: File) => {
const requestId = ++previewRequestIdRef.current;
@ -976,12 +996,13 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
[hasVectorPreview],
);
// Re-group text when grouping mode changes
// Re-group text when grouping mode changes without forcing a full reload
useEffect(() => {
if (loadedDocument) {
resetToDocument(loadedDocument, groupingMode);
const currentDocument = loadedDocumentRef.current;
if (currentDocument) {
resetToDocument(currentDocument, groupingMode);
}
}, [groupingMode, loadedDocument, resetToDocument]);
}, [groupingMode, resetToDocument]);
const viewData = useMemo<PdfJsonEditorViewData>(() => ({
document: loadedDocument,
@ -1089,19 +1110,13 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
return () => {
// Clear backend cache if we were using lazy loading
if (cachedJobId) {
console.log(`[PdfJsonEditor] Cleaning up cached document for jobId: ${cachedJobId}`);
apiClient.post(`/api/v1/convert/pdf/json/clear-cache/${cachedJobId}`).catch((error) => {
console.warn('[PdfJsonEditor] Failed to clear cache:', error);
});
}
clearCachedJob(cachedJobIdRef.current);
clearCustomWorkbenchViewData(VIEW_ID);
unregisterCustomWorkbenchView(VIEW_ID);
setLeftPanelView('toolPicker');
};
}, [
cachedJobId,
clearCachedJob,
clearCustomWorkbenchViewData,
registerCustomWorkbenchView,
setCustomWorkbenchViewData,