Bug: PDF Viewer broken — POST /documents response format mismatch
PLEASE CHECK FIRST BEFORE IMPLEMENTING! I stumbled on this issue, so I asked Claude 4.6 to fix it. And it did at least for me.
Summary
The PDF Viewer page shows "No PDF documents found" even when PDF documents exist and are correctly stored in the database. The root cause is a response format mismatch: PDFViewer.tsx expects POST /documents to return a plain JSON array, but the endpoint now returns a paginated object wrapper.
Environment
- Deployment: Docker (self-hosted)
- Image:
ghcr.io/morphik-org/morphik-core:latest
- UI:
node:22-alpine with ee/ui-component volume mount
- Date observed: 2026-02-13
Symptoms
- PDF Viewer section displays "No PDF documents found"
- "View in PDF Viewer" button from DocumentDetail does nothing
- Browser console shows:
All documents received: undefined
Error fetching documents: TypeError: t.filter is not a function
POST /documents returns HTTP 200 with valid data
- Documents page works correctly (lists all documents including PDFs)
Root Cause
File: ee/ui-component/components/pdf/PDFViewer.tsx, line 682
The fetchAvailableDocuments function does:
const allDocuments = await response.json();
// ...
const pdfDocuments = allDocuments
.filter((doc) => doc.content_type === "application/pdf")
But POST /documents now returns a paginated response object:
{
"documents": [...],
"skip": 0,
"limit": 50,
"returned_count": 53,
"total_count": 53,
"has_more": false,
"next_skip": null,
"status_counts": null,
"folder_counts": null
}
Calling .filter() on this object throws TypeError: t.filter is not a function.
Fix
One-line change in ee/ui-component/components/pdf/PDFViewer.tsx at line 682:
Before:
const allDocuments = await response.json();
After:
const _rawData = await response.json();
const allDocuments = Array.isArray(_rawData) ? _rawData : _rawData.documents || [];
This handles both the old array format and the new paginated object format.
Verification
Confirmed fix works: after patching, the PDF Viewer correctly lists all PDF documents and opens them for viewing.
Additional Context
The Documents section (DocumentsWithHeader / DocumentList) works correctly because it uses a different code path that already handles the paginated response format. Only the PDF Viewer component was missed when the API response format was updated.
Bug: PDF Viewer broken —
POST /documentsresponse format mismatchPLEASE CHECK FIRST BEFORE IMPLEMENTING! I stumbled on this issue, so I asked Claude 4.6 to fix it. And it did at least for me.
Summary
The PDF Viewer page shows "No PDF documents found" even when PDF documents exist and are correctly stored in the database. The root cause is a response format mismatch:
PDFViewer.tsxexpectsPOST /documentsto return a plain JSON array, but the endpoint now returns a paginated object wrapper.Environment
ghcr.io/morphik-org/morphik-core:latestnode:22-alpinewithee/ui-componentvolume mountSymptoms
POST /documentsreturns HTTP 200 with valid dataRoot Cause
File:
ee/ui-component/components/pdf/PDFViewer.tsx, line 682The
fetchAvailableDocumentsfunction does:But
POST /documentsnow returns a paginated response object:{ "documents": [...], "skip": 0, "limit": 50, "returned_count": 53, "total_count": 53, "has_more": false, "next_skip": null, "status_counts": null, "folder_counts": null }Calling
.filter()on this object throwsTypeError: t.filter is not a function.Fix
One-line change in
ee/ui-component/components/pdf/PDFViewer.tsxat line 682:Before:
After:
This handles both the old array format and the new paginated object format.
Verification
Confirmed fix works: after patching, the PDF Viewer correctly lists all PDF documents and opens them for viewing.
Additional Context
The Documents section (
DocumentsWithHeader/DocumentList) works correctly because it uses a different code path that already handles the paginated response format. Only the PDF Viewer component was missed when the API response format was updated.